From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Is it possible for a macro to expand to nothing? Date: Mon, 23 Nov 2009 12:12:59 -0800 Message-ID: <293F4C71CC134ED4BD182A552738F43E@us.oracle.com> References: <87r5rpccbh.fsf@galatea.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1259008959 8473 80.91.229.12 (23 Nov 2009 20:42:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 23 Nov 2009 20:42:39 +0000 (UTC) To: "'Pascal J. Bourguignon'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 23 21:42:32 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 1NCfjz-0000AJ-Bj for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 21:42:31 +0100 Original-Received: from localhost ([127.0.0.1]:59306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfjy-0007v5-GS for geh-help-gnu-emacs@m.gmane.org; Mon, 23 Nov 2009 15:42:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCfIk-0002Jj-79 for help-gnu-emacs@gnu.org; Mon, 23 Nov 2009 15:14:22 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCfIf-0002Iv-Df for help-gnu-emacs@gnu.org; Mon, 23 Nov 2009 15:14:21 -0500 Original-Received: from [199.232.76.173] (port=35111 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCfIf-0002Ik-3G for help-gnu-emacs@gnu.org; Mon, 23 Nov 2009 15:14:17 -0500 Original-Received: from rcsinet12.oracle.com ([148.87.113.124]:57778 helo=rgminet12.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NCfIe-0002FG-OH for help-gnu-emacs@gnu.org; Mon, 23 Nov 2009 15:14:16 -0500 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rgminet12.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nANKE8qq011840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 23 Nov 2009 20:14:10 GMT Original-Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nANKG16o024039; Mon, 23 Nov 2009 20:16:06 GMT Original-Received: from abhmt021.oracle.com by acsmt353.oracle.com with ESMTP id 547746701259007177; Mon, 23 Nov 2009 12:12:57 -0800 Original-Received: from dradamslap1 (/130.35.178.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Nov 2009 12:12:57 -0800 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87r5rpccbh.fsf@galatea.local> Thread-Index: AcpsdP/5UqF0POi3Sw2VGTDSPxcpqQAAV27w X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: acsmt358.oracle.com [141.146.40.158] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A0B0207.4B0AED13.02E1:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) 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:70059 Archived-At: > > (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). ((setq bar 2)) is then spliced in, because of ,@. And that produces the requested code. > When it is used outside of a macro, that produces an error. '((setq bar 2)) produces the list ((setq bar 2)) anywhere you evaluate it. > 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. It's simple, really: The code resulting from macroexpansion is a list. Just splice a list into the list you are building, instead of adding an element to it. If the list you splice in is (), then nothing is added to the list. (setq a1 '(M) a2 ()) (macroexpand `(x ,@a1)) = (x M) (macroexpand `(x ,@a2)) = (x) That's really all there is to it: instead of trying to add or not add M, splice in (M) or ().