help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Is it possible for a macro to expand to nothing?


From: Drew Adams
Subject: RE: Is it possible for a macro to expand to nothing?
Date: Mon, 23 Nov 2009 10:51:20 -0800

> >> you can do that by producing nil and then using ,@ inside a
> >> backquote. IOW, instead of inserting nil, you splice it in,
> >> which means inserting nothing.

> That wouldn't work, backquote is a quote.

Sorry, but it works just fine. I do this all the time.

You snipped out the code I suggested. Here it is again, with `and' substituted
for `ifdef' (which is undefined).

(defmacro titi (fn)
  `(defun ,fn ()
    (setq bar 1)
    ,@(and baz '((setq bar 2)))))

(let ((baz nil)) (titi foo))
(symbol-function 'foo) -> (lambda nil (setq bar 1))

(let ((baz t)) (titi foo))
(symbol-function 'foo) ->
  (lambda nil
    (setq bar 1)
    (setq bar 2))

That looks to me like just what Alan asked for.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]