diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-12-10 22:48:34 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-12-10 22:48:34 -0800 |
commit | c58a1a16de19700543700b24dd42dd3c234493b7 (patch) | |
tree | 931d74c98ebb9c5f76ab93ea1df67863700ee85a /txr.1 | |
parent | 8220c2ea55a59bee7bfdef3b5c9b180005ef95ee (diff) | |
download | txr-c58a1a16de19700543700b24dd42dd3c234493b7.tar.gz txr-c58a1a16de19700543700b24dd42dd3c234493b7.tar.bz2 txr-c58a1a16de19700543700b24dd42dd3c234493b7.zip |
symbol-function semantics change; new symbol-macro.
* eval.c (symbol_function): Only retrieve function binding,
and not macro or operator bindings, unless compatibility
<= 127 is in effect.
(symbol_macro): New function.
(fboundp): Only test for existence of function, not
macro or operator, unless <= 127 compatibility is in effect.
(fmakunbound): Do not remove macro binding, unless
compatibility <= 127 is in effect.
(eval_init): Register sys:top-mb variable for use in place.tl
library module. Register symbol-macro intrinsic function.
* share/txr/stdlib/place.tl (sys:get-mb): New function
(symbol-macro): New syntactic place.
* txr.1: Updated incorrect documentation about environments
from the perspective that macros and functions coexist.
Documented symbol-macro. Updated symbol-function, fboundp
and fmakunbound documentation. Added missing documentation
for mmakunbound. Reference to fboundp under define-place-macro
revised to mboundp. Added compatibility notes.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 184 |
1 files changed, 145 insertions, 39 deletions
@@ -10324,6 +10324,7 @@ defined by \*(TX programs. .mets >> [ obj-place < index <> [ alt ]] ;; equivalent to dwim .mets (symbol-value << symbol ) .mets (symbol-function << symbol ) +.mets (symbol-macro << symbol ) .mets (fun << function-name ) .mets (force << promise ) .mets (errno) @@ -10412,18 +10413,36 @@ the value which existed in that place prior to deletion. \*(TL is a Lisp-2 dialect: it features separate namespaces for functions and variables. -.NP* Global Functions and Macros +.NP* Global Functions and Operator Macros + +In \*(TL, global functions and operator macros co-exist, meaning that the same +symbol can be defined as both a macro and a function. There is a global namespace for functions, -into which functions and macros can be introduced with the -.codn defun -and -.code defmacro -operators. The global function environment can be inspected and -modified using the +into which functions can be introduced with the +.code defun +macro. The global function environment can be inspected and modified using the .code symbol-function accessor. +There is a global namespace for macros, into which +macros are introduced with the +.code defmacro +macro. The global function environment can be inspected and modified using the +.code symbol-macro +accessor. + +If a name +.code x +is defined as both a function and a macro, then an expression of the form +.code (x ...) +is expanded by the macro, whereas an expression of the form +.code [x ...] +refers to the function. Moreover, the macro can produce a call to the +function. The expression +.code (fun x) +will retrieve the function object. + .NP* Global and Dynamic Variables There is a global namespace for variables also. @@ -10475,12 +10494,54 @@ Macros receive an environment parameter with which they may expand forms in their correct environment, and perform some limited introspection over that environment in order to determine the nature of bindings, or the classification of forms in those environments. This introspection -is provided by +is provided by .codn lexical-var-p , .codn lexical-fun-p , and .codn lexical-lisp1-binding . +Lexical operator macros and lexical functions can also co-exist in the +following way. A lexical function shadows a global or lexical macro +completely. However, the reverse is not the case. A lexical macro shadows +only those uses of a function which look like macro calls. This is +succinctly demonstrated by the following form: + +.cblk + (flet ((foo () 43)) + (macrolet ((foo () 44)) + (list (fun foo) (foo) [foo]))) + + -> (#<interpreted fun: lambda nil> 44 43) +.cble + +The +.code (fun foo) +and +.code [fun] +expressions are oblivious to the macro; the macro expansion process +process the symbol +.code foo +in those contexts. However the form +.code (foo) +is subject to macro-expansion and replaced with +.codn 44 . + +If the +.code flet +and +.code macrolet +are reversed, the behavior is different: + +.cblk + (macrolet ((foo () 44)) + (flet ((foo () 43)) + (list (fun foo) (foo) [foo]))) + + -> (#<interpreted fun: lambda nil> 43 43) +.cble + +All three forms refer to the function, which lexically shadows the macro. + .NP* Pattern Language and Lisp Scope Nesting \*(TL expressions can be embedded in the \*(TX pattern language in various @@ -13013,11 +13074,13 @@ value is updated with .codn value . .SS* Global Environment -.coNP Accessors @ symbol-function and @ symbol-value +.coNP Accessors @, symbol-function @ symbol-macro and @ symbol-value .synb .mets (symbol-function << symbol ) +.mets (symbol-macro << symbol ) .mets (symbol-value << symbol ) .mets (set (symbol-function << symbol ) << new-value ) +.mets (set (symbol-macro << symbol ) << new-value ) .mets (set (symbol-value << symbol ) << new-value ) .syne .desc @@ -13031,27 +13094,30 @@ if it has one: that is, the function object bound to the .metn symbol . If .meta 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 +has no global function binding, then .code nil is returned. -The value of a macro binding isn't a function object, but a list of the -following form: +The +.code symbol-macro +function retrieves the value of the global macro binding of +.meta symbol +if it has one. The value of a macro binding isn't a function object, but a +list of the following form: .cblk .mets (#<environment object> < macro-parameter-list << body-form *) .cble -The value of a special operator binding is a "C pointer" object, whose -printed representation looks like: +This representation is likely to change or expand to include other +forms in future \*(TX versions. -.cblk - #<cptr: 808be4f> -.cble - -These details may change in future version of \*(TX. +Note: the name of this function has nothing to do with symbol macros; +it is named for consistency with +.code symbol-function +and +.codn symbol-value , +referring to the "macro-expander binding of the symbol cell". The .code symbol-value @@ -13061,17 +13127,9 @@ symbol macro, whichever exists. Otherwise it returns The value of a symbol macro binding is simply the replacement form. -.TP* "Dialect note:" -Forms which call -.code symbol-function -or -.code symbol-value -are currently not assignable places. Only the -.code defun -operator defines functions. - A -.code symbol-function +.codn symbol-function , +.codn symbol-macro , or .code symbol-value form denotes a place. If @@ -13087,6 +13145,16 @@ functions. If a nonexistent place is deleted, the prior value yielded by the deletion is deemed to be .codn nil . +.TP* "Dialect note:" + +In ANSI Common Lisp, the +.code symbol-function +function retrieves a function, macro or special operator binding. +These are all in one space and may not co-exist. In \*(TL, it +retrieves strictly a function binding. The +.code symbol-macro +function doesn't exist in Common Lisp. + .coNP Functions @, boundp @, fboundp and @ mboundp .synb .mets (boundp << symbol ) @@ -13104,10 +13172,23 @@ environment, otherwise .code fboundp returns .code t -if the symbol has a function or operator macro binding in the global -environment, or if it is a special operator, otherwise +if the symbol has a function binding in the global +environment, otherwise it returns nil .codn nil . +.TP* "Dialect Note:" + +The ANSI Common Lisp +.code fboundp +yields true if its argument has a function, macro or operator +binding. The behavior of the Common Lisp expression +.code (fboundp x) +in Common Lisp can be obtained in \*(TL using the +.cblk + (or (fboundp x) (mboundp x) (special-operator-p x)) +.cble +expression. + .code mboundp returns .code t @@ -13115,10 +13196,11 @@ if the symbol has an operator macro binding in the global environment, otherwise .codn nil . -.coNP Functions @ makunbound and @ fmakunbound +.coNP Functions @, makunbound @ fmakunbound and @ mmakunbound .synb .mets (makunbound << symbol ) .mets (fmakunbound << symbol ) +.mets (mmakunbound << symbol ) .syne .desc The function @@ -13151,14 +13233,23 @@ has no such binding, it does nothing. In either case, it returns .metn symbol . -Both functions and macros are bindings in the function namespace. +The function +.code mmakunbound +removes any binding for +.meta symbol +from the operator macro namespace of the global environment. If +.meta symbol +has no such binding, it does nothing. +In either case, it returns +.metn symbol . .TP* "Dialect Note:" The behavior of these functions differs from ANSI Common Lisp. + The .code makunbound -function in ANSI Lisp only removes a value from a dynamic variable. The +function in Common Lisp only removes a value from a dynamic variable. The dynamic variable does not cease to exist, it only ceases to have a value (because a binding is a value). The special property from a symbol is also not removed. In \*(TL, the variable ceases to exist. The binding @@ -13166,6 +13257,15 @@ of a variable isn't its value, it is the variable itself: the association between a name and an abstract storage location, in some environment. If the binding is undone, the variable disappears. +The +.code fmakunbound +function in Common Lisp removes a function or macro binding, which +do not coexist. + +The +.code mmakunbound +function doesn't exist in Common Lisp. + .coNP Function @ func-get-form .synb .mets (func-get-form << func ) @@ -25557,9 +25657,7 @@ The form does not cause .meta name to become -.code fboundp -or -.codn boundp . +.codn mboundp . There can exist both an ordinary macro and a place macro of the same name; moreover, this is potentially useful. @@ -38382,6 +38480,14 @@ of these version values, the described behaviors are provided if is given an argument which is equal or lower. For instance .code -C 103 selects the behaviors described below for version 105, but not those for 102. +.IP 127 +In versions of \*(TX until 127, the functions +.codn symbol-function , +.code fboundp +and +.code fmakunbound +behaved similarly to their Common Lisp counterparts. See the Dialect Notes +under these functions. .IP 124 In \*(TX 124 and earlier versions, the .code @(next) |