From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: macro temp variables Date: Sun, 21 Sep 2014 22:59:47 +0200 Organization: Informatimago Message-ID: <87iokgwuyk.fsf@kuiper.lan.informatimago.com> References: <87sijny0ph.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1411333530 10301 80.91.229.3 (21 Sep 2014 21:05:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 21:05:30 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Sep 21 23:05:22 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XVoJt-0004pV-K9 for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 23:05:21 +0200 Original-Received: from localhost ([::1]:40947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVoJt-0002Bk-6w for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 17:05:21 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 57 Original-X-Trace: individual.net gGdulA+SFkGWYyCUxIbqYgdbFwhP+OCfMR1b78VbnS2IDXshgj Cancel-Lock: sha1:YmVkY2M1YjVjYjEwZGZmNzAwNmU0ZTcyZWY5MzViMTI4M2I3MDA4NA== sha1:rNDi/16Un/6RyBTrTCBOYvKT8A4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:207827 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100101 Archived-At: Eric Abrahamsen writes: > "Pascal J. Bourguignon" writes: > >> Eric Abrahamsen writes: >> >>> I've never actually needed to write a macro that provided temporary >>> local variables, and consequently am not very good at it. Despite having >>> read the docs and basically followed the examples there, my attempt is >>> producing errors. > >> The problem is that you want your body to access those variables. So >> the body must know their names. But you are computing new names that >> are uninterned, and therefore unaccessible. Therefore there's no way to >> access those temporary variables, from the body. Only code generated by >> your macro could access those variables (since the macro has their name >> stored in its head .. tags variables. > > Wow, thanks so much to both of you, this is an excellent lesson in using > macros. Richard, the walk-through was much appreciated -- things like > that always start out seeming obvious, but then by step three or so I'm > perplexed. pp-macroexpand-* will be helpful in the future. > > So I think I've got it. The behavior that everyone's trying to avoid by > using make-symbol is in fact the precise behavior I want: leaking > symbols from the macro into the body code. I'm going to hold my brain > perfectly still until that sinks in. > > I had suspected that I'd have to do something along the lines of > Pascal's solution -- explicitly providing the args to be bound on each > pass -- but I'm inclined to go with Richard's version, since the whole > point of this function is to be a *scratch*-buffer way of doing one-off > things with Org headings, and I'd like it to be as easy to write as > possible. Then you would just bind those normal, interned, symbols, and document that your macro does this binding: (defmacro org-iterating-headings (&rest body) "Binds the following lexical variables: head item todo tags body-ars to the corresponding org headings, while iterating headings." (destructuring-bind (head item todo tags body-pars) vars `(call-org-iterating-headings (lambda (head item todo tags body-pars) ,@body)))) Notice the advantage of factoring yout the call-org-iterating-heading function: you can easily change the user interface of your macro after the fact, and even provide both. -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk