|
x-engine-c v0.2.13
The C engine for x-lang
|
Syntax - Binding Forms (def, set!) More...
#include "x-prim.h"#include "x-alist.h"#include "x-eval.h"#include "x-env.h"#include "x-type/symbol.h"Functions | |
| static x_obj_t * | x_prim_define (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_set (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_syntax_binding_register (x_obj_t *p_base, x_obj_t *p_args) |
Syntax - Binding Forms (def, set!)
Define form. x-lang: (def name value)
Binds name to the evaluated value in the CURRENT environment (fexpr – name is not evaluated, value is explicitly evaluated). That is the whole rule: at top level the current environment is the root, in a procedure body it is the call's own environment, in an operative body the operative's, and under (eval form e) it is e. A name the environment already binds is rebound in place; a parent's binding of the same name is left alone and shadowed.
| p_base | Base (execution context). |
| p_args | Unevaluated argument list; expects (caller name value). |
Eval-before-bind. The value expression is evaluated BEFORE the name is bound, so the value expression cannot reference the binding being created. A recursive definition still works, because a closure body resolves names at call time and the binding is in the environment by then.
Mutation form. x-lang: (set! name value)
Mutates the existing binding of name to the evaluated value (fexpr – name is not evaluated, value is explicitly evaluated). The binding is the one symbol evaluation would find: the current environment's, or the nearest ancestor's. Signals an error if the symbol is unbound.
| p_base | Base (execution context). |
| p_args | Unevaluated argument list; expects (caller name value). |