The following grammar for quasiquote expressions is not context-free.
It is presented as a recipe for generating an infinite number of
production rules. Imagine a copy of the following rules for D = 1, 2,
3, . D keeps track of the nesting depth.
[58] quasiquotation = quasiquotation_1
[59] template_0 = expression
[60] quasiquotation_D = &grave.template_D
| (quasiquote template_D)
[61] template_D = simple-datum
| list-template_D
| unquotation_D
[62] list-template_D = (template-or-splice_D*)
| (template-or-splice_D+ . template_D)
| 'template_D
| quasiquotation_D+1
[63] unquotation_D = ,template_D-1
| (unquote template_D-1)
[64] template-or-splice_D = template_D
| splicing-unquotation_D
[65] splicing-unquotation_D = ,template_D-1
| (unquote-splicing template_D-1)
In quasiquotations, a list-template_D may sometimes
be confused with either an unquotation_D or a
splicing-unquotation_D. The interpretation as an
unquotation or splicing-unquotation_D takes precedence.
Backquote or quasiquote expressions are useful
for constructing a list structure when most but not all of the
desired structure is known in advance. If no
commas appear within the template, the result of evaluating
&grave.template is equivalent to the result of evaluating
'template. If a comma appears within the
template, however, the expression following the comma is
evaluated (unquoted), and its result is inserted into the structure
instead of the comma and the expression. If a comma appears followed
immediately by an at-sign (), then the following
expression shall evaluate to a list; the opening and closing parentheses
of the list are then stripped away and the elements of the list are
inserted in place of the comma at-sign expression sequence.
&grave.(list ,(+ 1 2) 4) (list 3 4)
(let ((name 'a)) &grave.(list ,name ',name))
(list a (quote a))
&grave.(a ,(+ 1 2) ,(map abs '(4 -5 6)) b)
(a 3 4 5 6 b)
&grave.((foo ,(- 10 3)) ,(cdr '(c)) . ,(car '(cons)))
((foo 7) . cons)
Quasiquote forms may be nested. Substitutions are made only for
unquoted components appearing at the same nesting level
as the outermost backquote. The nesting level increases by one inside
each successive quasiquotation and decreases by one inside each
unquotation.
&grave.(a &grave.(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
(a &grave.(b ,(+ 1 2) ,(foo 4 d) e) f)
(let ((name1 'x)
(name2 'y))
&grave.(a &grave.(b ,,name1 ,',name2 d) e))
(a &grave.(b ,x ,'y d) e)
The notations &grave.template
and (quasiquote template) are identical in all respects.
,expression is identical to (unquote expression),
and ,expression is identical to
(unquote-splicing expression).
(quasiquote (list (unquote (+ 1 2)) 4)) (list 3 4)
'(quasiquote (list (unquote (+ 1 2)) 4))
&grave.(list ,(+ 1 2) 4) i.e., (quasiquote (list (unquote (+ 1 2)) 4))
Unpredictable behavior may result if any of the symbols
quasiquote, unquote, or unquote-splicing appear in
positions within a template other than as described above.