From 96a062025a5509b48d1fb0cf48db783229ef40c4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 11 Dec 2013 07:32:17 -0800 Subject: * eval.c (symbol_value, boundp, fboundp): New functions. (eval_init): New functions registred as intrinsics. * txr.1: Documented. --- ChangeLog | 7 +++++++ eval.c | 19 +++++++++++++++++++ txr.1 | 35 +++++++++++++++++++++++++++++------ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8c49f6d..c42adde9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-12-11 Kaz Kylheku + + * eval.c (symbol_value, boundp, fboundp): New functions. + (eval_init): New functions registred as intrinsics. + + * txr.1: Documented. + 2013-12-11 Kaz Kylheku * arith.c, hash.c, lib.c, rand.c, stream.c, syslog.c: Removing diff --git a/eval.c b/eval.c index 9bb509ef..a14d56d2 100644 --- a/eval.c +++ b/eval.c @@ -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)); diff --git a/txr.1 b/txr.1 index 08da5065..329a1431 100644 --- a/txr.1 +++ b/txr.1 @@ -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-value ) .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 ) + (fboundp ) + +.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 -- cgit v1.2.3