How can I fix the simple macro foo
in (elisp)Eval During Expansion?
None of the followings work:
(defmacro foo1 (a)
`(setq (eval ,a) t))
(defmacro foo2 (a)
`(setq ,(eval a) t))
(defmacro foo3 (a)
`(setq ,a t))
I really don't get what's said in (elisp)Eval During Expansion. I think if I got it, I'd have been able to fix the macro.
Update: huaiyuan's solution works:
(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)