emacs lisp宏扩展期间的求值

emacs lisp宏扩展期间的求值,emacs,macros,elisp,Emacs,Macros,Elisp,如何修复中的简单宏foo 以下各项均无效: (defmacro foo1 (a) `(setq (eval ,a) t)) (defmacro foo2 (a) `(setq ,(eval a) t)) (defmacro foo3 (a) `(setq ,a t)) 我真的不明白你在说什么。我想如果我得到它,我就可以修复宏了 更新:怀远解决方案工程: (defmacro foo7 (a) `(set ,a t)) (setq x 'b a 'c) (fo

如何修复中的简单宏
foo

以下各项均无效:

(defmacro foo1 (a)
  `(setq (eval ,a) t))

(defmacro foo2 (a)
  `(setq ,(eval a) t))

(defmacro foo3 (a)
  `(setq ,a t))
我真的不明白你在说什么。我想如果我得到它,我就可以修复宏了

更新:怀远解决方案工程:

(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 foo (aVeryLongAndImprobablyConflictingName)
   (list 'setq (eval aVeryLongAndImprobablyConflictingName) t))
“正确”的解决方案是不要求在宏扩展功能中评估用户提供的参数

(第4(a)条) `(setq,at))

尽管这与foo1、foo2或foo3都不一样。您试图解决的问题是什么?

试试看

(defmacro foo7 (a) `(set ,a t)) (第7(a)条) `(一套,一套)
elisp的语义在实现中常常是偶然的。作为一个经过深思熟虑、明确指定的宏系统的例子,我推荐。

您的foo4看起来和foo3一样。的确如此!我甚至找过了!