summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-28 05:53:27 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-28 05:53:27 -0700
commit422a4cde1940f5d63e349e73e7241c6e2e28b253 (patch)
treed682731c232bb932850eb6a7b95f63086f432f2e
parentd80d25d7bffd8e4dbf8a43870046bc256a12cd66 (diff)
downloadtxr-422a4cde1940f5d63e349e73e7241c6e2e28b253.tar.gz
txr-422a4cde1940f5d63e349e73e7241c6e2e28b253.tar.bz2
txr-422a4cde1940f5d63e349e73e7241c6e2e28b253.zip
New special macro parameter list parameter :form.
* eval.c (form_k): New keyword symbol variable. (bind_macro_params): Implement form_k. (eval_init): Initialize form_k. * txr.1: Documented :form parameter.
-rw-r--r--eval.c11
-rw-r--r--txr.131
2 files changed, 30 insertions, 12 deletions
diff --git a/eval.c b/eval.c
index bff81a48..6fe44e68 100644
--- a/eval.c
+++ b/eval.c
@@ -98,7 +98,7 @@ val fbind_s, lbind_s, flet_s, labels_s;
val opip_s, oand_s, chain_s, chand_s;
val sys_load_s, sys_lisp1_value_s;
-val special_s, whole_k, symacro_k;
+val special_s, whole_k, form_k, symacro_k;
val last_form_evaled, last_form_expanded;
@@ -765,7 +765,7 @@ static val bind_macro_params(val env, val menv, val params, val form,
while (consp(params)) {
val param = car(params);
- if (param == whole_k || param == env_k) {
+ if (param == whole_k || param == form_k || param == env_k) {
val nparam;
val next = cdr(params);
if (!next)
@@ -776,7 +776,11 @@ static val bind_macro_params(val env, val menv, val params, val form,
err_sym = nparam;
goto nbind;
}
- env_vbind_special(new_env, nparam, if3(param == whole_k, whole, menv),
+ env_vbind_special(new_env, nparam,
+ if3(param == whole_k,
+ whole,
+ if3(param == form_k,
+ ctx_form, menv)),
specials, ctx_form);
params = cdr(next);
continue;
@@ -4189,6 +4193,7 @@ void eval_init(void)
symacrolet_s = intern(lit("symacrolet"), user_package);
with_saved_vars_s = intern(lit("with-saved-vars"), system_package);
whole_k = intern(lit("whole"), keyword_package);
+ form_k = intern(lit("form"), keyword_package);
special_s = intern(lit("special"), system_package);
symacro_k = intern(lit("symacro"), keyword_package);
prof_s = intern(lit("prof"), user_package);
diff --git a/txr.1 b/txr.1
index b3dd7451..885bdb11 100644
--- a/txr.1
+++ b/txr.1
@@ -22277,24 +22277,30 @@ and
receive
.codn nil .
-Macro parameter lists also support two special keywords, namely
-.code :env
+Macro parameter lists also supports two special keywords, namely
+.codn :env ,
+.code :whole
and
-.codn :whole .
+.codn :form .
The parameter list
-.code (:whole x :env y)
+.code (:whole x :env y :form z)
will bind parameter
.code x
to the entire
-macro parameter list, and bind parameter
+macro parameter list, bind parameter
.code y
-to the macro environment.
+to the macro environment and bind parameter
+.code z
+to the entire macro form (the original compound form used to invoke the
+macro).
+
The
+.codn :env ,
.code :whole
and
-.code :env
-notation can occur anywhere in a macro parameter list, other than
+.code :form
+notations can occur anywhere in a macro parameter list, other than
to the right of the consing dot.
.TP* "Dialect Note:"
@@ -22324,7 +22330,14 @@ they are the same and behave the same way. Thus
is treated the same way in macros as in
.code tree-bind
and related binding operators: it binds just the arguments
-to the parameter.
+to the parameter. \*(TL has the special parameter
+.code :form
+by means of which macros can access their invoking form.
+This parameter is also supported in
+.code tree-bind
+and binds to the entire
+.code tree-bind
+form.
.coNP Operator @ macro-time
.synb