diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-03-02 22:04:16 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-03-02 22:04:16 -0800 |
commit | cb4b820893b2cc48a70f2a2f0d70863fb191d7aa (patch) | |
tree | f6a6b004d2dfe0daec6b0a726c53817780601949 | |
parent | e23eefb30af6f88ca18887131c547a545c9edbef (diff) | |
download | txr-cb4b820893b2cc48a70f2a2f0d70863fb191d7aa.tar.gz txr-cb4b820893b2cc48a70f2a2f0d70863fb191d7aa.tar.bz2 txr-cb4b820893b2cc48a70f2a2f0d70863fb191d7aa.zip |
* eval.c (make_env_intrinsic): New static function.
(eval_init): Register new intrinsics make-env, env-fbind and env-vbind.
* txr.1: Documented.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | eval.c | 15 | ||||
-rw-r--r-- | txr.1 | 43 |
3 files changed, 65 insertions, 0 deletions
@@ -1,5 +1,12 @@ 2014-03-02 Kaz Kylheku <kaz@kylheku.com> + * eval.c (make_env_intrinsic): New static function. + (eval_init): Register new intrinsics make-env, env-fbind and env-vbind. + + * txr.1: Documented. + +2014-03-02 Kaz Kylheku <kaz@kylheku.com> + Version 83 * txr.c (version): Bumped. @@ -100,6 +100,18 @@ val make_env(val vbindings, val fbindings, val up_env) return env; } +/* + * Wrapper for performance reasons: don't make make_env + * process default arguments. + */ +static val make_env_intrinsic(val vbindings, val fbindings, val up_env) +{ + vbindings = default_bool_arg(vbindings); + fbindings = default_bool_arg(fbindings); + up_env = default_bool_arg(up_env); + return make_env(vbindings, fbindings, up_env); +} + val env_fbind(val env, val sym, val fun) { val cell; @@ -3309,6 +3321,9 @@ void eval_init(void) func_n2o(macroexpand_1, 1)); reg_fun(intern(lit("macroexpand"), user_package), func_n2o(macroexpand, 1)); + reg_fun(intern(lit("make-env"), user_package), func_n3o(make_env_intrinsic, 0)); + reg_fun(intern(lit("env-fbind"), user_package), func_n3(env_fbind)); + reg_fun(intern(lit("env-vbind"), user_package), func_n3(env_vbind)); reg_fun(intern(lit("chain"), user_package), func_n0v(chainv)); reg_fun(intern(lit("andf"), user_package), func_n0v(andv)); reg_fun(intern(lit("orf"), user_package), func_n0v(orv)); @@ -5802,6 +5802,49 @@ resolving the function and variable references encountered in the expression. The object nil can be specified as an environment, in which case the evaluation takes place in the global environment. +See also: the make-env function. + +.SS Function make-env + +.TP +Syntax: + + (make-env [<variable-bindings> [<function-bindings> [<next-env>]]]) + +.TP +Description: + +The make-env function creates an environment object suitable as the <env> parameter. + +The <variable-bindings> and <function-bindings> parameters, if specified, +should be association lists, mapping symbols to objects. The objects in +<function-bindings> should be functions, or objects callable as functions. + +The <next-env> argument, if specified, should be an environment. + +Note: bindings can also be added to an environment usign the env-vbind +and env-fbind functions. + +.SS Functions env-vbind and env-fbind + +.TP +Syntax: + + (env-vbind <env> <symbol> <value>) + (env-fbind <env> <symbol> <value>) + +.TP +Description: + +These functions bind a symbol to a value in either the function or variable space +of environment <env>. + +Values established in the function space should be functions or objects that +can be used as functions such as lists, strings, arrays or hashes. + +If <symbol> already exists in the environment, in the given space, then its +value is updated with <value>. + .SH MUTATION .SS Operators inc, dec, set, push, pop, flip and del |