summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--eval.c9
-rw-r--r--txr.135
3 files changed, 44 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index d2351387..b6c1a7e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2014-02-22 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (symbol_function): Retrieve the global macro binding if the
+ function lookup fails, and if that fails, retrieve the special
+ operator binding.
+ (fboundp): Report t if there is a global macro binding.
+
+ * txr.1: Use "global" rather than "toplevel". Added note that
+ the fun operator doesn't see macro bindings. Documented that
+ symbol-function and fboundp see global macro bindings,
+ and that symbol-function can retrieve a special operator binding.
+
+2014-02-22 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (prinl, pprinl): New functions.
(eval_init): Registered as intrinsics.
diff --git a/eval.c b/eval.c
index 9a30b391..baa0ed73 100644
--- a/eval.c
+++ b/eval.c
@@ -2522,7 +2522,10 @@ static val symbol_value(val sym)
static val symbol_function(val sym)
{
- return cdr(lookup_fun(nil, sym));
+ uses_or2;
+ return or2(cdr(or2(lookup_fun(nil, sym),
+ lookup_mac(nil, sym))),
+ gethash(op_table, sym));
}
static val boundp(val sym)
@@ -2532,8 +2535,8 @@ static val boundp(val sym)
static val fboundp(val sym)
{
- return if3(lookup_fun(nil, sym), t,
- if3(gethash(op_table, sym), t, nil));
+ return if2(lookup_fun(nil, sym) || lookup_mac(nil, sym) ||
+ gethash(op_table, sym), t);
}
static val rangev_func(val env, val lcons)
diff --git a/txr.1 b/txr.1
index 285b3bce..8089616e 100644
--- a/txr.1
+++ b/txr.1
@@ -6189,10 +6189,14 @@ Syntax:
.TP
Description:
The fun operator retrieves the function object corresponding to a named
-function.
-. The <function-name> is a symbol denoting a named function: a built in
+function in the current lexical environment.
+
+The <function-name> is a symbol denoting a named function: a built in
function, or one defined by defun.
+Note: the fun operator does not see macro bindings. It is possible to
+retrieve a global macro expander using symbol-function.
+
.TP
Dialect Note:
A lambda expression is not a function name in TXR Lisp. The
@@ -6209,20 +6213,33 @@ Syntax:
.TP
Description:
-The symbol-function retrieves the value of the toplevel function binding of the
+The symbol-function retrieves the value of the global 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 has no global function binding, then the value of the global macro
+binding is returned. If that doesn't exist, then the value of a global special
+operator binding is returned, and if that doesn't exist, then nil is returned.
-The symbol-value retrives the value of a toplevel variable, if it exists,
+The symbol-value retrives the value of a global variable, if it exists,
otherwise nil.
+Note: a function binding is a function, but a macro or special operator binding
+binding isn't. The value of a macro binding is a list of the following form:
+
+ (#<environment object> <macro-parameter-list> <body-form>*)
+
+The value of a special operator binding is a "C pointer" object, whose
+printed representation looks like:
+
+ #<cptr: 808be4f>
+
+These details may change in future version of TXR.
+
.TP
Dialect note:
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.
+operator modifies variables.
.SS Functions boundp and fboundp
@@ -6235,10 +6252,10 @@ Syntax:
.TP
Description:
-boundp returns t if the symbol has a variable binding in the toplevel
+boundp returns t if the symbol has a variable binding in the global
environment, otherwise nil.
-Foundp returns t if the symbol has a function binding in the toplevel
+Foundp returns t if the symbol has a function or macro binding in the global
environment, or if it is an operator, otherwise nil.
.SS Function func-get-form