From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Is it possible for a macro to expand to nothing? Date: Mon, 23 Nov 2009 21:08:04 +0100 Organization: Informatimago Message-ID: <87my2dc8d7.fsf@galatea.local> References: <87vdh1ccra.fsf@galatea.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259010149 12524 80.91.229.12 (23 Nov 2009 21:02:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 23 Nov 2009 21:02:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 23 22:02:03 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NCg2s-0000fi-F7 for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 22:02:02 +0100 Original-Received: from localhost ([127.0.0.1]:55906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCg2s-0005wS-59 for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 16:02:02 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 60 Original-X-Trace: individual.net uoBatbUlAm1enrrPsHn2gA0gK1M98o/gcsNU6TDsQFB5TisVxC Cancel-Lock: sha1:ZWE5MDM3ZTZmOWU1Yzk2YmE4OWJhOTI0NWU2YTJiMTRmNzUwZjQyNA== sha1:a3Ts9bti9jogL/rmqYOdf7iRbD0= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:174988 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70060 "Drew Adams" writes: >> >> 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. No, it doesn't: (defmacro ifdef (expr &rest body) (and (eval expr) `(progn ,@body))) (ifdef t ((setq bar 2))) --> Debugger entered--Lisp error: (invalid-function (setq bar 2)) ((setq bar 2)) (progn ((setq bar 2))) (ifdef t ((setq bar 2))) eval((ifdef t ((setq bar 2)))) eval-last-sexp-1((4)) eval-last-sexp((4)) call-interactively(eval-last-sexp) > You snipped out the code I suggested. Here it is again, with `and' substituted > for `ifdef' (which is undefined). > > (defmacro titi (fn) I didn't say that it didn't work inside titi. I said that it was a bad idea to take the habit of giving an invalid form to a macro to get an invalid form from it. Notice also my alternative solution uses macroexpand. This is a clue that if you want to go that way, you should use a function rather than a macro: (defun %parenthesized-ifdef (expr forms) (if expr '() `((progn ,@forms)))) (defmacro titi (fn) `(defun ,fn () (setq bar 1) ,@(%parenthesized-ifdef baz '((setq bar 2))))) (macroexpand '(titi foo)) --> (defun foo nil (setq bar 1) (progn (setq bar 2))) -- __Pascal Bourguignon__