summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-19 18:36:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-19 18:36:18 -0800
commitaacf701d451639f393d964e7bd60e18d24a7f68d (patch)
tree16a00d2efb6fe171fdcdb81ddbd32edde2bba763 /txr.1
parent72c88930b62b9bc64804048b9759bc7ed95cd789 (diff)
downloadtxr-aacf701d451639f393d964e7bd60e18d24a7f68d.tar.gz
txr-aacf701d451639f393d964e7bd60e18d24a7f68d.tar.bz2
txr-aacf701d451639f393d964e7bd60e18d24a7f68d.zip
Allow global macros to be denoted by (macro sym).
In this patch we allow (symbol-function '(macro sym)), (defun (macro sym) (form env) ...), and (trace (macro sym)). * eval.c (macro_s): New symbol variable. (lookup_fun, func_get_name, op_defun): Support (macro sym) syntax. (builtin_reject_test): Pass through (macro sym) syntax. (eval_init); Initialize macro_s. * share/txr/stdlib/place.tl (sys:get-fun-getter-setter): Support macro place. * txr.1: Documented verything.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.186
1 files changed, 74 insertions, 12 deletions
diff --git a/txr.1 b/txr.1
index b3831fbb..8b1b31eb 100644
--- a/txr.1
+++ b/txr.1
@@ -12354,11 +12354,13 @@ and
.code nil
may not be used as function names. Neither can keyword symbols.
-It is possible to define methods with
+It is possible to define methods as well as macros with
.codn defun ,
as an alternative to the
.code defmeth
-macro.
+and
+.code defmacro
+forms.
To define a method, the syntax
.cblk
@@ -12366,15 +12368,35 @@ To define a method, the syntax
.cble
should be used as the argument to the
.meta name
-parameter.
+parameter. This gives rise to the syntax
+.cblk
+.meti (defun (meth < type << name ) < args << form *)
+.cble
+which is equivalent to the
+.cblk
+.meti (defmeth < type < name < args << form *)
+.cble
+syntax.
-The syntax
+Macros can be defined using
.cblk
-.meti (defun (meth type name) args forms)
+.meti (macro << name )
.cble
-is equivalent to the
+as the
+.meta name
+parameter of
+.codn defun .
+This way of defining a macro doesn't support destructuring;
+it defines the expander as an ordinary function with an ordinary
+argument list. To work, the function must accept two arguments:
+the entire macro call form that is to be expanded, and the
+macro environment. Thus, the macro definition syntax is
+.cblk
+.meti (defun (macro << name ) < form < env << form *)
+.cble
+which is equivalent to the
.cblk
-.meti (defmeth type name args forms)
+.meti (defmacro < name (:form < form :env << env ) << form *)
.cble
syntax.
@@ -14854,9 +14876,11 @@ If
.meta symbol
has no global function binding, then
.code nil
-is returned. The
+is returned.
+
+The
.code symbol-function
-function also supports method names of the form
+function supports method names of the form
.cblk
.meti (meth < struct << slot )
.cble
@@ -14866,8 +14890,15 @@ names a struct type, and
.meta slot
a static slot. Names in this format are returned by the
.meta func-get-name
-function.
-
+function. The
+.code symbol-function
+function also supports names of the form
+.cblk
+.meti (macro << name )
+.cble
+which denote macros. Thus,
+.code symbol-function
+provides unified access to functions, methods and macros.
The
.code symbol-macro
@@ -15201,7 +15232,28 @@ symbols in the global environment resolve to the function,
it is not specified which one is returned.
If the global function environment search fails,
-then the function is considered as a possible method.
+then the function is considered as a possible macro.
+The global macro environment is searched for a macro
+binding whose expander function is
+.metn func ,
+similarly to the way the function environment was
+searched. If a binding is found, then the syntax
+.cblk
+.meti (macro << name )
+.cble
+is returned, where
+.meta name
+is the name of the global macro binding that was found
+which resolves to
+.metn func .
+If two or more global macro bindings share
+.metn func ,
+it is not specified which of those bindings provides
+.metn name .
+
+If the global macro search fails, then
+.meta func
+is considered as a possible method.
The static slot space of all struct types is searched for
a slot which contains
.metn func .
@@ -48576,6 +48628,16 @@ syntax: see the
.code func-get-name
function.
+Macros can be traced; their names are given using
+.cblk
+.meti (macro << name )
+.cble
+syntax. Note that
+.code trace
+will not show the destructured internal macro arguments, but only the
+two arguments passed to the expander function: the whole form, and the
+environment.
+
.SH* INTERACTIVE LISTENER
.SS* Overview