x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
binding.c File Reference

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_tx_prim_define (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_set (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_syntax_binding_register (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Syntax - Binding Forms (def, set!)

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Function Documentation

◆ x_prim_define()

static x_obj_t * x_prim_define ( x_obj_t p_base,
x_obj_t p_args 
)
static

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.

Parameters
p_baseBase (execution context).
p_argsUnevaluated argument list; expects (caller name value).
Returns
The evaluated 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.

See also
x_prim_set – mutation form (does not create bindings)
x_env_bind – the binder this is a form over

◆ x_prim_set()

static x_obj_t * x_prim_set ( x_obj_t p_base,
x_obj_t p_args 
)
static

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.

Parameters
p_baseBase (execution context).
p_argsUnevaluated argument list; expects (caller name value).
Returns
The evaluated value.
Note
Raises "Unbound symbol" if name has no existing binding.
See also
x_prim_define

◆ x_syntax_binding_register()

x_obj_t * x_syntax_binding_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register binding syntax primitives.

Binds: def, set!.

Parameters
p_baseBase (execution context).
p_argsUnused.
Returns
p_base.