diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | eval.c | 19 | ||||
-rw-r--r-- | txr.1 | 35 |
3 files changed, 55 insertions, 6 deletions
@@ -1,5 +1,12 @@ 2013-12-11 Kaz Kylheku <kaz@kylheku.com> + * eval.c (symbol_value, boundp, fboundp): New functions. + (eval_init): New functions registred as intrinsics. + + * txr.1: Documented. + +2013-12-11 Kaz Kylheku <kaz@kylheku.com> + * arith.c, hash.c, lib.c, rand.c, stream.c, syslog.c: Removing #include <assert.h> since none of these modules uses the standard C assert macro. @@ -1903,11 +1903,27 @@ static val lazy_mappendv(val fun, val list_of_lists) return lazy_appendv(lazy_mapcarv(fun, list_of_lists)); } +static val symbol_value(val sym) +{ + return cdr(lookup_var(nil, sym)); +} + static val symbol_function(val sym) { return cdr(lookup_fun(nil, sym)); } +static val boundp(val sym) +{ + return if3(lookup_var(nil, sym), t, nil); +} + +static val fboundp(val sym) +{ + return if3(lookup_fun(nil, sym), t, + if3(gethash(op_table, sym), t, nil)); +} + static val rangev_func(val env, val lcons) { cons_bind (from, to_step, env); @@ -2534,7 +2550,10 @@ void eval_init(void) reg_fun(intern(lit("refset"), user_package), func_n3(refset)); reg_fun(intern(lit("replace"), user_package), func_n4o(replace, 2)); + reg_fun(intern(lit("symbol-value"), user_package), func_n1(symbol_value)); reg_fun(intern(lit("symbol-function"), user_package), func_n1(symbol_function)); + reg_fun(intern(lit("boundp"), user_package), func_n1(boundp)); + reg_fun(intern(lit("fboundp"), user_package), func_n1(fboundp)); reg_fun(intern(lit("func-get-form"), user_package), func_n1(func_get_form)); reg_fun(intern(lit("func-get-env"), user_package), func_n1(func_get_env)); reg_fun(intern(lit("functionp"), user_package), func_n1(functionp)); @@ -5858,25 +5858,48 @@ Dialect Note: A lambda expression is not a function name in TXR Lisp. The syntax (fun (lambda ...)) is invalid. -.SS Function symbol-function +.SS Functions symbol-function and symbol-value .TP Syntax: (symbol-function <symbol>) + (symbol-value <symbol>) .TP Description: -The symbol-function retrieves the toplevel function binding of the given -symbol if it has one. If the symbol has no toplevel function binding, -the value nil is returned. +The symbol-function retrieves the value of the toplevel function binding of the +given symbol if it has one: that is, the function object tied to the symbol. If +the symbol has no toplevel function binding, the value nil is returned. + +The symbol-value retrives the value of a toplevel variable, if it exists, +otherwise nil. .TP Dialect note: -The symbol-function form is currently not an assignable place. Only -the defun operator defines functions. +Forms which call symbol-function or symbol-value are currently not an +assignable place. Only the defun operator defines functions, and the set +operator modifies variables. There is no way to modify a toplevel variable that +is shadowed by a lexical variable. + +.SS Functions boundp and fboundp + +.TP +Syntax: + + (boundp <symbol>) + (fboundp <symbol>) + +.TP +Description: + +boundp returns t if the symbol has a variable binding in the toplevel +environment, otherwise nil. + +Foundp returns t if the symbol has a function binding in the toplevel +environment, or if it is an operator, otherwise nil. .SS Function func-get-form |