summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c13
-rw-r--r--tests/010/qquote.tl30
-rw-r--r--txr.130
3 files changed, 73 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 81c7cdca..41777807 100644
--- a/eval.c
+++ b/eval.c
@@ -3661,6 +3661,7 @@ static val expand_qquote_rec(val qquoted_form, val qq, val unq, val spl)
return cons(quote_s, cons(qquoted_form, nil));
} else {
val sym = car(qquoted_form);
+ val args, uqform;
if (sym == spl) {
val error_msg = if3(spl == sys_splice_s,
@@ -3691,6 +3692,18 @@ static val expand_qquote_rec(val qquoted_form, val qq, val unq, val spl)
val opts = expand_qquote(second(qquoted_form), qq, unq, spl);
val keys = expand_qquote(rest(rest(qquoted_form)), qq, unq, spl);
return rlcp(list(tree_construct_s, opts, keys, nao), qquoted_form);
+ } else if (sym == expr_s && consp((args = cdr(qquoted_form)))
+ && !cdr(args) && consp((uqform = car(args))) &&
+ car(uqform) == unq && consp(cdr(uqform)) && !cddr(uqform))
+ {
+ val gs = gensym(nil);
+ val ret = list(let_s, cons(list(gs, cadr(uqform), nao), nil),
+ list(if_s, list(atom_s, gs, nao),
+ list(list_s, list(quote_s, var_s, nao),
+ gs, nao),
+ list(list_s, list(quote_s, expr_s, nao),
+ gs, nao), nao), nao);
+ return rlcp_tree(ret, qquoted_form);
} else {
val f = sym;
val r = cdr(qquoted_form);
diff --git a/tests/010/qquote.tl b/tests/010/qquote.tl
new file mode 100644
index 00000000..e6daad3a
--- /dev/null
+++ b/tests/010/qquote.tl
@@ -0,0 +1,30 @@
+(let ((nullsym nil)
+ (sym 's)
+ (atom "abc")
+ (cons '(x y z))
+ (dwim '[]))
+ (tree-bind (x y (op arg)) ^(a b @,nullsym)
+ (assert (eq op 'sys:var))
+ (assert (eq arg nullsym)))
+ (tree-bind (x y (op arg)) ^(a b @,sym)
+ (assert (eq op 'sys:var))
+ (assert (eq arg sym)))
+ (tree-bind (x y (op arg)) ^(a b @,atom)
+ (assert (eq op 'sys:var))
+ (assert (eq arg atom)))
+ (tree-bind (x y (op arg)) ^(a b @,cons)
+ (assert (eq op 'sys:expr))
+ (assert (eq arg cons)))
+ (tree-bind (x y (op arg)) ^(a b @,dwim)
+ (assert (eq op 'sys:expr))
+ (assert (eq arg dwim)))
+ (tree-bind (x y (op arg . tail)) ^(a b (sys:expr ,sym . foo))
+ (assert (eq op 'sys:expr))
+ (assert (eq arg sym))
+ (assert (eq tail 'foo)))
+ (tree-bind (x y (op arg0 arg1)) ^(a b (sys:expr ,sym foo))
+ (assert (eq op 'sys:expr))
+ (assert (eq arg0 sym))
+ (assert (eq arg1 'foo)))
+ (tree-bind (x y (op)) ^(a b (sys:expr))
+ (assert (eq op 'sys:expr))))
diff --git a/txr.1 b/txr.1
index 4ee8ba01..3439afbc 100644
--- a/txr.1
+++ b/txr.1
@@ -12175,6 +12175,36 @@ The expression
is evaluated to produce the list
.codn "(6 8)" ,
and this list is spliced into the quoted template.
+
+.meIP >> @,* expr
+This syntax is not a distinct quasiquoting operator, but rather the combination of
+an unquote occurring as a meta-expression, denoting the structure
+.codn "(sys:expr ,expr)" .
+This structure is treated specially by the quasiquote expander. Code is generated
+for it such that if
+.meta expr
+evaluates to an value
+.meta val
+which is an
+.codn atom ,
+then the result will be the
+.mono
+.meti (sys:var << val )
+.onom
+structure. If
+.meta val
+is a
+.code cons
+rather than an
+.codn atom ,
+then the result is the
+.mono
+.meti (sys:expr << val )
+.onom
+structure. In other words, when quasiquoting is used to insert a value under the
+.code @
+meta prefix, the expander generates code to analyze the type of the value, and
+produce to the form which is most likely intended.
.RE
.TP* "Dialect Notes:"