unquote
is only useful in the context of quasiquote
, and quasiquote
can be implemented as a macro (that uses quote
behind the scenes). So there's no need to have an unquote
primitive; the quasiquote
macro simply deals with unquote
symbols as they are found.
(quasiquote
is the Scheme name for the backtick quote. Thus:
`(foo bar ,baz)
is read in as
(quasiquote (foo bar (unquote baz)))
in Scheme.)
Here's a very simple Scheme quasiquote
macro (it only handles lists, unlike standard quasiquote
which also handles vectors and other data types):
(define-syntax quasiquote
(syntax-rules (unquote unquote-splicing)
((quasiquote (unquote datum))
datum)
((quasiquote ((unquote-splicing datum) . next))
(append datum (quasiquote next)))
((quasiquote (datum . next))
(cons (quasiquote datum) (quasiquote next)))
((quasiquote datum)
(quote datum))))
Equivalent version using all the standard reader abbreviations:
(define-syntax quasiquote
(syntax-rules (unquote unquote-splicing)
(`,datum
datum)
(`(,@datum . next)
(append datum `next))
(`(datum . next)
(cons `datum `next))
(`datum
'datum)))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…