summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c9
-rw-r--r--txr.151
2 files changed, 60 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 53fb6ad5..a5888e9f 100644
--- a/eval.c
+++ b/eval.c
@@ -2912,6 +2912,14 @@ static val me_qquote(val form, val menv)
return expand_qquote(second(form), qquote_s, unquote_s, splice_s);
}
+static val me_equot(val form, val menv)
+{
+ if (!cdr(form) || cddr(form))
+ eval_error(form, lit("~s: one argument required"), car(form));
+
+ return rlcp(cons(quote_s, cons(expand(cadr(form), menv), nil)), form);
+}
+
static val expand_vars(val vars, val menv, val form,
val *spec_p, int seq_p)
{
@@ -5068,6 +5076,7 @@ void eval_init(void)
reg_mac(aret_s, func_n2(me_ret_aret));
reg_mac(qquote_s, func_n2(me_qquote));
reg_mac(sys_qquote_s, func_n2(me_qquote));
+ reg_mac(intern(lit("equot"), user_package), func_n2(me_equot));
reg_mac(intern(lit("pprof"), user_package), func_n2(me_pprof));
reg_mac(when_s, func_n2(me_when));
reg_mac(intern(lit("unless"), user_package), func_n2(me_unless));
diff --git a/txr.1 b/txr.1
index 40eb7ffa..add132ad 100644
--- a/txr.1
+++ b/txr.1
@@ -27990,6 +27990,57 @@ emanating from the
.code delta
form.
+.coNP Macro @ equot
+.synb
+.mets (equot << form )
+.syne
+.desc
+The
+.code equot
+macro ("expand and quote") performs a full expansion of
+.code form
+in the surrounding macro environment. Then it constructs a
+.code quote
+form whose argument is the expansion. This quote form is
+then returned as the macro replacement for the original
+.code equot
+form.
+
+.TP* Example:
+
+.cblk
+ (symacrolet ((a (+ 2 2)))
+ (list (quote a) (equot a) a))
+ --> (a (+ 2 2) 4)
+.cble
+
+Above, the expansion of
+.code a
+is
+.codn "(+ 2 2)" .
+Thus the macro call
+.code "(equot a)"
+expands to
+.codn "(quote (+ 2 2))" .
+When that is evaluated, it yields
+.codn "(+ 2 2)" .
+
+If
+.code a
+is quoted, then of course the result is
+.codn a :
+no expansion or evaluation takes place.
+Whereas if
+.code a
+is presented for evaluation, then not only is it expanded to
+.codn "(+ 2 2)" ,
+but that expansion is reduced to 4.
+
+The
+.code equot
+operator is a mongrel of these two semantics: it permits expansion to proceed,
+but then suppresses evaluation of the result.
+
.coNP Operators @ tree-bind and @ mac-param-bind
.synb
.mets (tree-bind < macro-style-params < expr << form *)