In the expression:
`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
that evaluates to
(a (quasiquote (b (unquote (+ 1 2)) (unquote (foo 4 d)) e)) f)
Why (+ 1 3) is evaluated and (+ 1 2) not?
The commas are associated to the closest quasiquote. The comma of ,(+ 1
2) is associated to the quasiquote before (b, which is inside the
quasiquote before (a. Therefore it cannot be evaluated, since it is
(quasi)quoted. On the other hand, the comma of ,(+ 1 3) being inside an
unquote form, is associated to the quasiquote before (a, and it can be
evaluated.
Clearly, comma means unquote. It's like parentheses.
`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
(quote (a
(quote (b
(unquote (+ 1 2)) ; quote quote unquote --> quote
(unquote (foo ; quote quote unquote --> quote
(unquote (+ 1 3)) ; quote quote unquote unquote --> eval
d)) ; quote quote unquote --> quote
e)) ; quote quote --> quote quote
f)) ; quote --> quote
--
__Pascal Bourguignon__
Good explanation. Thank you.