help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macro temp variables


From: Eric Abrahamsen
Subject: Re: macro temp variables
Date: Sun, 21 Sep 2014 12:37:36 +0800
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux)

"Pascal J. Bourguignon" <address@hidden> writes:

> Eric Abrahamsen <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]