【发布时间】:2009-11-10 12:08:49
【问题描述】:
如何修复(elisp)Eval During Expansion 中的简单宏foo?
以下都不起作用:
(defmacro foo1 (a)
`(setq (eval ,a) t))
(defmacro foo2 (a)
`(setq ,(eval a) t))
(defmacro foo3 (a)
`(setq ,a t))
我真的不明白(elisp)Eval During Expansion 中所说的内容。我想如果我得到它,我就可以修复宏了。
更新:怀远的解决方案有效:
(defmacro foo7 (a)
`(set ,a t))
(setq x 'b
a 'c)
(foo7 x)
(assert (eq b t))
(assert (eq x 'b))
(foo7 a)
(assert (eq a 'c))
(assert (eq c t))
(macroexpand '(foo7 x)) ; ==> (set x t)
(macroexpand '(foo7 a)) ; ==> (set a t)
【问题讨论】: