gpt4 book ai didi

emacs - emacs lisp 宏扩展期间的 eval

转载 作者:行者123 更新时间:2023-12-02 02:36:06 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com