From: Sam Steingold
Subject: nested macrolets
Date: 
Message-ID: <d95970b4.0308081251.13bc5965@posting.google.com>
I am confused by an apparently simple form:

(symbol-macrolet ((foo 12))
  (macrolet ((bar (x) (+ x foo)))
    (bar 10)))

is this legal?
(note that I _do_ want FOO in BAR definition to be evaluated
at BAR's _macroexpansion_ time, not at run time).
in general, how do get a local macro (or a local symbol-macro, like FOO)
evaluated at macroexpansion time of another macro?

thanks.

From: Erann Gat
Subject: Re: nested macrolets
Date: 
Message-ID: <gat-0808031601000001@k-137-79-50-101.jpl.nasa.gov>
In article <····························@posting.google.com>, ···@usa.net
(Sam Steingold) wrote:

> I am confused by an apparently simple form:
> 
> (symbol-macrolet ((foo 12))
>   (macrolet ((bar (x) (+ x foo)))
>     (bar 10)))
> 
> is this legal?

Of course.  Why would you doubt it?

> (note that I _do_ want FOO in BAR definition to be evaluated
> at BAR's _macroexpansion_ time, not at run time).

Ah, that is an entirely different issue than whether the form is legal.

There are two problems with this desire.  First, symbol macros always
expand to literals (i.e. symbol macros can't perform computations the way
real macros can) so it's not really meaningful (except for debugging) to
say that a symbol macro has been expanded at any particular time.

Second, there isn't a formal distinction between macroexpand time and run
time in Common Lisp.  Nothing prevents an implementaiton from expanding a
macro afresh every time it is run.

> in general, how do get a local macro (or a local symbol-macro, like FOO)
> evaluated at macroexpansion time of another macro?

You'd have to build this behavior into a particular implementation.

Given that you are one of the developers of CLisp I can't help but wonder
why you are asking these questions.  Surely you know all these things
already?

E.
From: Barry Margolin
Subject: Re: nested macrolets
Date: 
Message-ID: <1kOZa.108$7R.97@news.level3.com>
In article <····················@k-137-79-50-101.jpl.nasa.gov>,
Erann Gat <···@jpl.nasa.gov> wrote:
>Second, there isn't a formal distinction between macroexpand time and run
>time in Common Lisp.  Nothing prevents an implementaiton from expanding a
>macro afresh every time it is run.

When the compiler is used, there *is* a formal distinction between
macroexpand time and run time.  Macros must be expanded at compile time.

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Duane Rettig
Subject: Re: nested macrolets
Date: 
Message-ID: <4bruwp16x.fsf@beta.franz.com>
Barry Margolin <··············@level3.com> writes:

> In article <····················@k-137-79-50-101.jpl.nasa.gov>,
> Erann Gat <···@jpl.nasa.gov> wrote:
> >Second, there isn't a formal distinction between macroexpand time and run
> >time in Common Lisp.  Nothing prevents an implementaiton from expanding a
> >macro afresh every time it is run.
> 
> When the compiler is used, there *is* a formal distinction between
> macroexpand time and run time.  Macros must be expanded at compile time.

Although your correction goes the right direction, it is a little
ambiguous, and might overshoot the mark if anyone misinterprets
the phrase "when the compiler is used".  Just as there is a distinction
between macroexpand time and run time, there is also a distinction
between macroexpand time and compile time.

To be precise, Macros are always expanded at macroexpand time (unless
an explicit call is made to macroexpand or macroexpand-1, of course).
If an implementation has both a compiler (mandated) and an interpreter
(optional), then macroexpand time occurs under two circumstances:

 1. As one phase at compile time, which means that no macroexpansion
will occur when the (compiled) form is run.  Note that macroexpansion
might happen multiple times on the same form, but only during the
compilation.

 2. As one phase of evaluation of the lisp form, which means that
macroexpansion might occur as often as the form is evaluated.

Note also that eval-when processing might cause macroexpansion to
occur in both situations for the same form.

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Erann Gat
Subject: Re: nested macrolets
Date: 
Message-ID: <gat-1108031033560001@k-137-79-50-101.jpl.nasa.gov>
In article <·············@beta.franz.com>, Duane Rettig <·····@franz.com> wrote:

> Barry Margolin <··············@level3.com> writes:
> 
> > In article <····················@k-137-79-50-101.jpl.nasa.gov>,
> > Erann Gat <···@jpl.nasa.gov> wrote:
> > >Second, there isn't a formal distinction between macroexpand time and run
> > >time in Common Lisp.  Nothing prevents an implementaiton from expanding a
> > >macro afresh every time it is run.
> > 
> > When the compiler is used, there *is* a formal distinction between
> > macroexpand time and run time.  Macros must be expanded at compile time.
> 
> Although your correction goes the right direction, it is a little
> ambiguous, and might overshoot the mark if anyone misinterprets
> the phrase "when the compiler is used".  Just as there is a distinction
> between macroexpand time and run time, there is also a distinction
> between macroexpand time and compile time.
> 
> To be precise, Macros are always expanded at macroexpand time (unless
> an explicit call is made to macroexpand or macroexpand-1, of course).
> If an implementation has both a compiler (mandated) and an interpreter
> (optional), then macroexpand time occurs under two circumstances:
> 
>  1. As one phase at compile time, which means that no macroexpansion
> will occur when the (compiled) form is run.  Note that macroexpansion
> might happen multiple times on the same form, but only during the
> compilation.
> 
>  2. As one phase of evaluation of the lisp form, which means that
> macroexpansion might occur as often as the form is evaluated.
> 
> Note also that eval-when processing might cause macroexpansion to
> occur in both situations for the same form.

I stand corrected.

I had thought that "run time" meant "when the program is run" but it
doesn't.  It is a formally defined term in the CL spec, and it applies
only to compiled code.  Mea culpa.

E.
From: Kent M Pitman
Subject: Re: nested macrolets
Date: 
Message-ID: <sfwsmobwkmw.fsf@shell01.TheWorld.com>
···@usa.net (Sam Steingold) writes:

> I am confused by an apparently simple form:
> 
> (symbol-macrolet ((foo 12))
>   (macrolet ((bar (x) (+ x foo)))
>     (bar 10)))
> 
> is this legal?

It's legal.  It just doesn't mean what you probably mean it to mean. ;)

> (note that I _do_ want FOO in BAR definition to be evaluated
> at BAR's _macroexpansion_ time, not at run time).
> in general, how do get a local macro (or a local symbol-macro, like FOO)
> evaluated at macroexpansion time of another macro?

(symbol-macrolet ((foo 12))
  (macrolet ((bar (x) (symbol-macrolet ((foo 12))
                        (+ x foo))))
    (bar 10)))

:-)

See the dictionary entry for macrolet -- The bodies of the local macros
have no access to the lexical environment and cannot use bound function
and variable names.  In effect, symbol-macrolet manipulates bound variable
names.
From: Alexey Dejneka
Subject: Re: nested macrolets
Date: 
Message-ID: <m3bruzms8y.fsf@comail.ru>
···@usa.net (Sam Steingold) writes:

> I am confused by an apparently simple form:
> 
> (symbol-macrolet ((foo 12))
>   (macrolet ((bar (x) (+ x foo)))
>     (bar 10)))
> 
> is this legal?

Yes. It is explicitly said so in CLHS, description of MACROLET:

CLHS> The macro-expansion functions defined by macrolet are defined in
CLHS> the lexical environment in which the macrolet form
CLHS> appears. Declarations and macrolet and symbol-macrolet definitions
CLHS> affect the local macro definitions in a macrolet,

-- 
Regards,
Alexey Dejneka

"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer
From: Kent M Pitman
Subject: Re: nested macrolets
Date: 
Message-ID: <sfwn0eifn0s.fsf@shell01.TheWorld.com>
Alexey Dejneka <········@comail.ru> writes:

> Yes. It is explicitly said so in CLHS, description of MACROLET:
> 
> CLHS> The macro-expansion functions defined by macrolet are defined in
> CLHS> the lexical environment in which the macrolet form
> CLHS> appears. Declarations and macrolet and symbol-macrolet definitions
> CLHS> affect the local macro definitions in a macrolet,

Oops.  You're right here, in spite of what I said in another message.

(It's funny because I was looking at the same paragraph, even the same
sentence, when I responded before and didn't see that it mentioned
symbol-macrolet; I think it might be because of the way the browser
changes the colors of visited links and maybe I skipped over the
differently colored text...?)