From cb4b820893b2cc48a70f2a2f0d70863fb191d7aa Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 2 Mar 2014 22:04:16 -0800 Subject: * eval.c (make_env_intrinsic): New static function. (eval_init): Register new intrinsics make-env, env-fbind and env-vbind. * txr.1: Documented. --- ChangeLog | 7 +++++++ eval.c | 15 +++++++++++++++ txr.1 | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/ChangeLog b/ChangeLog index d20328c5..a4b3a790 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-03-02 Kaz Kylheku + + * 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 Version 83 diff --git a/eval.c b/eval.c index be60544b..7936da92 100644 --- a/eval.c +++ b/eval.c @@ -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)); diff --git a/txr.1 b/txr.1 index 853a6988..173d2d41 100644 --- a/txr.1 +++ b/txr.1 @@ -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 [ [ []]]) + +.TP +Description: + +The make-env function creates an environment object suitable as the parameter. + +The and parameters, if specified, +should be association lists, mapping symbols to objects. The objects in + should be functions, or objects callable as functions. + +The 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-fbind ) + +.TP +Description: + +These functions bind a symbol to a value in either the function or variable space +of environment . + +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 already exists in the environment, in the given space, then its +value is updated with . + .SH MUTATION .SS Operators inc, dec, set, push, pop, flip and del -- cgit v1.2.3