all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to define a macro correctly?
@ 2010-10-18 19:19 Johan Andersson
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Andersson @ 2010-10-18 19:19 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 739 bytes --]

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!

[-- Attachment #2: Type: text/html, Size: 1045 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread
[parent not found: <mailman.8.1287429628.15066.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2010-10-19  1:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-18 19:19 How to define a macro correctly? Johan Andersson
     [not found] <mailman.8.1287429628.15066.help-gnu-emacs@gnu.org>
2010-10-19  1:39 ` Barry Margolin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.