emacs - emacs lisp 宏扩展期间的 eval

标签 emacs macros elisp

如何修复简单的宏 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/

相关文章:

c++ - GCC/CLANG 预处理器与 MSVC 之间的差异是什么?

sorting - 如何让 Emacs 按长度对行进行排序?

Emacs 口齿不清 : get sub-matches from a regexp match

emacs 主要模式字符之间的字体锁定(括号、引号等)

Emacs:打印命令的键绑定(bind)或列出所有键绑定(bind)

c - 为 C 结构定义 gdb 打印函数

c++ - 在字符串文字内展开宏

compilation - proc宏能否确定调用编译的目标?

html - 使用 Emacs 将非 ASCII 字符替换为 SGML 实体代码

emacs - 错误的类型参数 : stringp, nil