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: Thu, 26 Nov 2009 12:11:10 +0100 Organization: Informatimago Message-ID: <87ocmp7d81.fsf@galatea.local> References: <87ljhwb2dx.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 1259235770 29171 80.91.229.12 (26 Nov 2009 11:42:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Nov 2009 11:42:50 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 26 12:42:43 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 1NDckE-0003FH-Ro for geh-help-gnu-emacs@m.gmane.org; Thu, 26 Nov 2009 12:42:43 +0100 Original-Received: from localhost ([127.0.0.1]:58680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDckE-0003pj-6O for geh-help-gnu-emacs@m.gmane.org; Thu, 26 Nov 2009 06:42:42 -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: 94 Original-X-Trace: individual.net LpDJTC0rjaq02MiZKjMgmQQfOUYA/JOc0SJvg8QsQy6P2EczLj Cancel-Lock: sha1:Zjk4MDQ4NjBiYWNkODg2ZmEyYmQ3YThhY2M5MmQ0MTEzNTczMTcxMw== sha1:y/zj3HmHoOm16z42woNhlEJqumU= 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:175072 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:70142 Archived-At: Alan Mackenzie writes: > Jeff Clough wrote: >> From: Alan Mackenzie >> Date: Tue, 24 Nov 2009 16:39:20 +0000 (UTC) > >>>> It comes directly from the definition of defmacro, > >>>> defmacro is a special form in `src/eval.c'. >>>> (defmacro name arglist [docstring] [decl] body...) > >>>> Define name as a macro. The actual definition looks like >>>> (macro lambda arglist [docstring] [decl] body...). >>>> When the macro is called, as in (name ARGS...), the function >>>> (lambda arglist body...) is applied to the list ARGS... as it >>>> appears in the expression, and the result should be a form to be >>>> evaluated instead of the original. > >>> Oh, come on! That last sentence is a tutorial, motivating one, >>> expressed in the slightly loose, colloquial language of the hacker. >>> "a form to be evaluated" is here shorthand for something like "some >>> sort of atom or list structure which fits into the slot where the >>> invocation is housed" > >> This is incorrect. The term "form" has a very specific definition in >> Lisp. It is a sexp that can be evaluated. While I'm new to Lisp, I >> have been knee deep in books and documents for the last couple of weeks >> and everything (including the GNU Emacs Lisp Manual) presents macros as >> a way to generate *forms*, not just sexps. > > You've missed my point. The guy who wrote that definition of macro was, > in using the word "form", being somewhat, er, informal. It was just > easier and more concise to say "form" than "form or (sometimes) other > appropriate list structure". He was informal only as much as the "emacs lisp reference manual" doesn't contain a glossary entry for "form". The reason why is that because at the time emacs was invented, it was a well known technical term established for 30 years meaning "an executable sexp". Only a few years later did Common Lisp get formalized with a normalizing glossary, where you can find the formal definition for form which I cited. Notice that it is justified to retrofit most definitions of the Common Lisp glossary to the older lisps, since Common Lisp is after all not much more than the GCD of the lisps that existed at the time. >> If you have a macro that expands to (1 2 3), it's not going to break >> the world, but that macro isn't doing what every hacker is going to >> expect. I'd call that a style problem. > > Just like somebody occasionally using a goto in C. Pascal was unable to > identify any specific problem a non-form macro expansion causes. I cited several times the reason why it's bad: because the macro form cannot be used stand alone without signaling an error. Jeff says the same. You could ask on comp.lang.lisp where I'd bet you'd get even more gurus answering. (Real lisp gurus intervene sometimes on cll). >> If, for some reason, you absolutely have to use a macro to generate >> something like that above, at least have it expand to (list 1 2 3), >> that way the macro can still be evaluated and no one gets shafted. > > And waste run time evaluating that list every time the defun runs? That depends on what you're doing. But indeed, by advice is to use a _function_ to return (1 2 3) and avoid rebuilding the list several time. >> You get the behavior you want and the macro is still expanding to a >> valid form. > > Nobody has yet given a valid reason why I should care about a macro > expansion being a "valid form" when the invoker is not going to evaluate > it. cc-langs.el is chock full of such "invalid forms", yet they make the > maintenance of 7 complicated language modes tractable. It is a _style_ reason. A question of good taste. The same reason why you don't poop in your living room. It would be bad style. To make an analogy, there is a room where you can defecate, there's a room where you watch TV. Technically, there's no reason why you shouldn't be able to defecate in your living room, but for style reasons (and because you don't have to paper over it later), it's better if you keep defecating in your water closed room. -- __Pascal Bourguignon__