如何修复简单的宏 foo
在 (elisp)Eval During Expansion ?
以下方法均无效:
(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)
最佳答案
尝试
(defmacro foo7 (a)
`(设置,a t))
elisp 的语义通常是实现的偶然性。作为一个经过深思熟虑、明确指定的宏系统的例子,我推荐 Common Lisp's .
关于emacs - emacs lisp 宏扩展期间的 eval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1707499/