[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to define a macro correctly?
From: |
Johan Andersson |
Subject: |
How to define a macro correctly? |
Date: |
Mon, 18 Oct 2010 21:19:46 +0200 |
Hey,
I want to create a macro that sets a variable value and then executes body. I know how to solve it, but I want to know which way is the best (more correct). I came up with these solutions:
a)
(defmacro mac (&rest body)
`(progn
(setq var t)
,@body))
b)
(defmacro mac (&rest body)
(setq var t)
`(progn ,@body))
c)
(defmacro mac (&rest body)
(cons 'progn (cons (list 'setq 'var t) body)))
I noticed that (using macroexpand) macro a and c expands to the same list. b however sets the variable in the macro and then only return the list body. What does that mean exactly, that I set the variable in the macro and do not return it as a list?
What way is the best? Or is there some other way that is better?
Thanks!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- How to define a macro correctly?,
Johan Andersson <=