Why does the nested quasiquote not unwrap splice-u

2019-07-29 18:05发布

Why does the first macro unquote-splicing not produce (quasiquote (unquote (quasiquote 1 2))), but the second example replaces the value?

(define x (list 1 2))
(t '(quasiquote (unquote (quasiquote (unquote-splicing x))))
   (quasiquote (quasiquote (unquote (quasiquote (unquote-splicing x))))))

(t '(quasiquote (unquote (quasiquote (unquote (1 2)))))
   (quasiquote (quasiquote (unquote (quasiquote (unquote (unquote x)))))))

标签: macros scheme
1条回答
女痞
2楼-- · 2019-07-29 18:40

In the first example

(quasiquote (quasiquote (unquote (quasiquote (unquote-splicing x)))))

This has 3 quasiquotes and 2 unquotes, so 'x' will not be evaluated.

in the second example

(quasiquote (quasiquote (unquote (quasiquote (unquote (unquote x))))))

there are 3 quasiquotes and 3 unquotes so 'x' will be replaced by it's value.

查看更多
登录 后发表回答