From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: macro temp variables Date: Sun, 21 Sep 2014 12:37:36 +0800 Message-ID: <878uldvban.fsf@ericabrahamsen.net> References: <87sijny0ph.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1411299511 14757 80.91.229.3 (21 Sep 2014 11:38:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Sep 2014 11:38:31 +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 13:38:26 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 1XVfTG-00036W-Gr for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 13:38:26 +0200 Original-Received: from localhost ([::1]:38895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfTG-0003I1-0d for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Sep 2014 07:38:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfSl-000389-9v for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:38:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVfSe-0002rA-W5 for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:37:55 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:35555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVfSe-0002py-Ql for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 07:37:48 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XVYpm-0004dp-Bb for help-gnu-emacs@gnu.org; Sun, 21 Sep 2014 06:33:14 +0200 Original-Received: from 50.56.99.223 ([50.56.99.223]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Sep 2014 06:33:14 +0200 Original-Received: from eric by 50.56.99.223 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 21 Sep 2014 06:33:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 50.56.99.223 User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:r0x7Cc8MdhDYtDxUgPW1xaDCeco= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:100092 Archived-At: "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. Thanks again! Eric