unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: macro temp variables
Date: Sun, 21 Sep 2014 12:37:36 +0800	[thread overview]
Message-ID: <878uldvban.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87sijny0ph.fsf@kuiper.lan.informatimago.com

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> 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




  parent reply	other threads:[~2014-09-21  4:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.9181.1411123560.1147.help-gnu-emacs@gnu.org>
2014-09-19 17:33 ` macro temp variables Pascal J. Bourguignon
2014-09-19 17:45   ` Stefan Monnier
     [not found]   ` <mailman.9214.1411148764.1147.help-gnu-emacs@gnu.org>
2014-09-19 18:51     ` Pascal J. Bourguignon
2014-09-21  4:37   ` Eric Abrahamsen [this message]
     [not found]   ` <mailman.9302.1411299483.1147.help-gnu-emacs@gnu.org>
2014-09-21 20:59     ` Pascal J. Bourguignon
2014-09-19 10:49 Eric Abrahamsen
2014-09-19 12:11 ` Nicolas Richard
2014-09-19 15:48   ` Nicolas Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878uldvban.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).