lval.h file

Contents

Functions

auto lval_num(long num) -> lval*
Creates an lval of type LVAL_NUM.
auto lval_err(const char* fmt, ...) -> lval*
Creates an lval of type LVAL_ERR.
auto lval_sym(const char* sym) -> lval*
Creates an lval of type LVAL_SYM.
auto lval_str(const char* str) -> lval*
TODO.
auto lval_sexpr(void) -> lval*
Creates an lval of type LVAL_SEXPR.
auto lval_qexpr(void) -> lval*
Creates an lval of type LVAL_QEXPR.
auto lval_fun(lbuiltin func) -> lval*
Constructs an lval of type LVAL_FUN.
auto lval_lambda(lval* formals, lval* body) -> lval*
Constructs a lambda lval.
void lval_del(lval* obj)
Frees an lval.
auto lval_add(lval* parent, lval* child) -> lval*
Adds the child l_arg to the parent obj.
auto lval_copy(const lval* obj) -> lval*
Copies an lval.
auto lval_pop(lval* obj, unsigned ith) -> lval*
Pops the ith element off of the lval obj.
auto lval_take(lval* obj, unsigned ith) -> lval*
Takes the ith element off of the lval obj.
auto lval_eval(lenv* env, lval* obj) -> lval*
Evaluates the lval obj.
auto lval_call(lenv* env, lval* func, lval* arg) -> lval*
TODO.
auto lval_eval_sexpr(lenv* env, lval* sexpr) -> lval*
Evaluates the lval obj as an S-Expression.
auto lval_join(lval* l_arg, lval* r_arg) -> lval*
Joins the Q-Expression r_arg to l_arg.
auto lval_eq(lval* l_arg, lval* r_arg) -> int
TODO.
auto load_prelude(lenv* env) -> lval*
TODO.

Function documentation

lval* lval_num(long num)

Creates an lval of type LVAL_NUM.

Parameters
num - type: const long
Returns lval*

Creates an lval of type LVAL_NUM and sets the obj to the provided number num.

lval* lval_err(const char* fmt, ...)

Creates an lval of type LVAL_ERR.

Parameters
fmt - type: char*
Returns lval*

Creates an lval of type LVAL_ERR and sets the obj to the provided error message l_arg.

lval* lval_sym(const char* sym)

Creates an lval of type LVAL_SYM.

Parameters
sym - type: char*
Returns lval*

Creates an lval of type LVAL_SYM and sets the obj to the provided symbol or operator l_arg.

lval* lval_sexpr(void)

Creates an lval of type LVAL_SEXPR.

Returns lval*

Creates an lval of type LVAL_SEXPR which is an empty S-Expression.

lval* lval_qexpr(void)

Creates an lval of type LVAL_QEXPR.

Returns lval*

Creates an lval of type LVAL_QEXPR which is an empty Q-Expression.

lval* lval_fun(lbuiltin func)

Constructs an lval of type LVAL_FUN.

Parameters
func - type: lbuiltin
Returns lval*

Constructs an lval of type LVAL_FUN and sets the obj to the provided builtin function func.

lval* lval_lambda(lval* formals, lval* body)

Constructs a lambda lval.

Parameters
formals - type: lval*
body - type: lval*
Returns lval*

Constructs a lambda lval.

void lval_del(lval* obj)

Frees an lval.

Parameters
obj - type: lval*

Frees an lval and all of its children (if any) as well as any other allocated resources.

lval* lval_add(lval* parent, lval* child)

Adds the child l_arg to the parent obj.

Parameters
parent - type: lval*
child - type: const lval*
Returns lval*

Adds the child l_arg to the parent obj. Allocates memory to obj's cell array and assigns l_arg to the last slot of the array.

lval* lval_copy(const lval* obj)

Copies an lval.

Parameters
obj - type: lval*
Returns lval*

Copies an lval and all of its children (if any) as well as any other allocated resources.

lval* lval_pop(lval* obj, unsigned ith)

Pops the ith element off of the lval obj.

Parameters
obj
ith - type: int
Returns lval*

Pops the ith element off of the lval obj and moves the receding elements up. Returns the popped element.

lval* lval_take(lval* obj, unsigned ith)

Takes the ith element off of the lval obj.

Parameters
obj - type: lval*
ith - type: int
Returns lval*

Takes the ith element off of the lval obj and discards all other objs. Returns the taken element.

lval* lval_eval(lenv* env, lval* obj)

Evaluates the lval obj.

Parameters
env - type: lenv*
obj - type: lval*
Returns lval*

Evaluates the lval obj. Returns obj as-is it is not an S-Expression.

lval* lval_eval_sexpr(lenv* env, lval* sexpr)

Evaluates the lval obj as an S-Expression.

Parameters
env - type: lenv*
sexpr - type: lval*
Returns lval*

Evaluates the lval obj as an S-Expression. Returns obj as-is if it has no children or returns the child if it only has one child. Returns an error if the child does not start with a symbol.

lval* lval_join(lval* l_arg, lval* r_arg)

Joins the Q-Expression r_arg to l_arg.

Parameters
l_arg - type: lval*
r_arg - type: lval*
Returns lval*

Joins the Q-Expression r_arg to l_arg by continually popping the first element off r_arg and adding it to l_arg. Returns l_arg.