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:21:36 +0100 Organization: Informatimago Message-ID: <87iqd1c7qn.fsf@galatea.local> References: <87r5rpccbh.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 1259010238 12871 80.91.229.12 (23 Nov 2009 21:03:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 23 Nov 2009 21:03:58 +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:03:49 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 1NCg4Y-0001RY-Bd for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 22:03:46 +0100 Original-Received: from localhost ([127.0.0.1]:56928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCg4X-0006uB-Tk for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 16:03:45 -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: 43 Original-X-Trace: individual.net +MaXzie9UPgupemsGKINxQaJ1AzK5Cvxumd2czypcXeNlai4yF Cancel-Lock: sha1:Y2ZlMzA3OWU2Y2EwMTRhMzVkN2RhMWU3YmQzZmE0YmU1YjAzZjEyNA== sha1:kUi/jweSWzXph4uusyE4m2DtIGk= 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:174991 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:70062 Archived-At: "Drew Adams" writes: >> > (defmacro titi (fn) >> > `(defun ,fn () >> > (setq bar 1) >> > ,@(ifdef baz '((setq bar 2)))))) >> > >> > Assuming that ifdef returns nil if baz is nil, that should >> > give you (defun foo () (setq bar 1)). If baz is not nil, >> > it should give you this: >> > >> > (defun foo () >> > (setq bar 1) >> > (setq bar 2)) >> >> Yes. Unfortunately, (ifdef baz '((setq bar 2))) doesn't produce a >> valid form when baz is not nil. > > Huh? It produces the list ((setq bar 2)), assuming `ifdef' acts like `and' > (`ifdef' is undefined AFAIK). Yes. And ((setq bar 2)) is not a valid form. So it is not a good idea, not a good style to call (ifdef baz '((setq bar 2))) and use its result like that. >> This is not a good property. It would be >> better to keep the contract of macros, that is they take code, and >> they produce code, that is, valid forms. > > No idea what you are talking about. Yes, that's the problem. > It's simple, really: The code resulting from macroexpansion is a list. No. CODE resulting from macroexpansion should be CODE. Not just a list. If you want to get random lists, then use functions, not macros. -- __Pascal Bourguignon__