From: ···········@gmail.com
Subject: MACROLET and lexical variables
Date: 
Message-ID: <ef7d8596-f0fc-4422-b21a-539adbed669b@h1g2000prh.googlegroups.com>
Kent Pitman suggested the following code, regarding a possible
implementation of an anonymous macro, in a previous post (http://
groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?
dmode=source):

(DEFMACRO META (&REST FORMS)
   (LET ((DO-IT (GENSYM "DO-IT")))
     `(MACROLET ((,DO-IT () ,@FORMS))
        (,DO-IT))))

but it seems to me that, according to the HyperSpec, this would not be
100% safe. Quote:

"The macro-expansion functions defined by macrolet are defined in the
lexical environment in which the macrolet form appears. Declarations
and macrolet and symbol-macrolet definitions affect the local macro
definitions in a macrolet, but the consequences are undefined if the
local macro definitions reference any local variable or function
bindings that are visible in that lexical environment."

In this case the ,@forms would be the suspect.

More here: http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html

Opinions?

From: Pascal Bourguignon
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <87k5j23hqs.fsf@thalassa.informatimago.com>
···········@gmail.com writes:

> Kent Pitman suggested the following code, regarding a possible
> implementation of an anonymous macro, in a previous post (http://
> groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?
> dmode=source):
>
> (DEFMACRO META (&REST FORMS)
>    (LET ((DO-IT (GENSYM "DO-IT")))
>      `(MACROLET ((,DO-IT () ,@FORMS))
>         (,DO-IT))))
>
> but it seems to me that, according to the HyperSpec, this would not be
> 100% safe. Quote:
>
> "The macro-expansion functions defined by macrolet are defined in the
> lexical environment in which the macrolet form appears. Declarations
> and macrolet and symbol-macrolet definitions affect the local macro
> definitions in a macrolet, but the consequences are undefined if the
> local macro definitions reference any local variable or function
> bindings that are visible in that lexical environment."
>
> In this case the ,@forms would be the suspect.
>
> More here: http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html
>
> Opinions?

Why FORMS and not DO-IT?
They've got equal status with respect to the macrolet form.

(macroexpand '(meta `(progn ,@(loop :repeat 5 :collect '(print 'hi)))))
--> (MACROLET ((#:DO-IT10523 NIL `(PROGN ,@(LOOP :REPEAT 5 :COLLECT '(PRINT 'HI)))))
      (#:DO-IT10523)) ;
    T

Now the question is what could be wrong in this macrolet form?
I see nothing wrong in it.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Specifications are for the weak and timid!"
From: ···········@gmail.com
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <872f72be-6e54-4903-be8b-ea57a40057a3@q10g2000prf.googlegroups.com>
On Apr 12, 11:06 pm, Pascal Bourguignon <····@informatimago.com>
wrote:
> ···········@gmail.com writes:
> > Kent Pitman suggested the following code, regarding a possible
> > implementation of an anonymous macro, in a previous post (http://
> > groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?
> > dmode=source):
>
> > (DEFMACRO META (&REST FORMS)
> >    (LET ((DO-IT (GENSYM "DO-IT")))
> >      `(MACROLET ((,DO-IT () ,@FORMS))
> >         (,DO-IT))))
>
> > but it seems to me that, according to the HyperSpec, this would not be
> > 100% safe. Quote:
>
> > "The macro-expansion functions defined by macrolet are defined in the
> > lexical environment in which the macrolet form appears. Declarations
> > and macrolet and symbol-macrolet definitions affect the local macro
> > definitions in a macrolet, but the consequences are undefined if the
> > local macro definitions reference any local variable or function
> > bindings that are visible in that lexical environment."
>
> > In this case the ,@forms would be the suspect.
>
> > More here:http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html
>
> > Opinions?
>
> Why FORMS and not DO-IT?
> They've got equal status with respect to the macrolet form.
>
> (macroexpand '(meta `(progn ,@(loop :repeat 5 :collect '(print 'hi)))))
> --> (MACROLET ((#:DO-IT10523 NIL `(PROGN ,@(LOOP :REPEAT 5 :COLLECT '(PRINT 'HI)))))
>       (#:DO-IT10523)) ;
>     T
>
> Now the question is what could be wrong in this macrolet form?
> I see nothing wrong in it.
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/
>
> "Specifications are for the weak and timid!"

"... the consequences are undefined if the
local macro definitions reference any local variable or function
bindings that are visible in that lexical environment."

That is what appears to be wrong.
From: Barry Margolin
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <barmar-513D10.17465212042008@newsgroups.comcast.net>
In article 
<····································@q10g2000prf.googlegroups.com>,
 ···········@gmail.com wrote:

> On Apr 12, 11:06 pm, Pascal Bourguignon <····@informatimago.com>
> wrote:
> > ···········@gmail.com writes:
> > > Kent Pitman suggested the following code, regarding a possible
> > > implementation of an anonymous macro, in a previous post (http://
> > > groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?
> > > dmode=source):
> >
> > > (DEFMACRO META (&REST FORMS)
> > >    (LET ((DO-IT (GENSYM "DO-IT")))
> > >      `(MACROLET ((,DO-IT () ,@FORMS))
> > >         (,DO-IT))))
> >
> > > but it seems to me that, according to the HyperSpec, this would not be
> > > 100% safe. Quote:
> >
> > > "The macro-expansion functions defined by macrolet are defined in the
> > > lexical environment in which the macrolet form appears. Declarations
> > > and macrolet and symbol-macrolet definitions affect the local macro
> > > definitions in a macrolet, but the consequences are undefined if the
> > > local macro definitions reference any local variable or function
> > > bindings that are visible in that lexical environment."
> >
> > > In this case the ,@forms would be the suspect.
> >
> > > More 
> > > here:http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html
> >
> > > Opinions?
> >
> > Why FORMS and not DO-IT?
> > They've got equal status with respect to the macrolet form.
> >
> > (macroexpand '(meta `(progn ,@(loop :repeat 5 :collect '(print 'hi)))))
> > --> (MACROLET ((#:DO-IT10523 NIL `(PROGN ,@(LOOP :REPEAT 5 :COLLECT '(PRINT 
> > 'HI)))))
> >       (#:DO-IT10523)) ;
> >     T
> >
> > Now the question is what could be wrong in this macrolet form?
> > I see nothing wrong in it.
> 
> "... the consequences are undefined if the
> local macro definitions reference any local variable or function
> bindings that are visible in that lexical environment."
> 
> That is what appears to be wrong.

You said you think ,@forms would be suspect, but it doesn't appear in 
the local macro definition.  It's in the original macro, but when that 
macro expands into a MACROLET it gets replaced with the forms.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: ···········@gmail.com
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <f0f95810-dba0-46d8-a5e3-3ac723aa3141@b9g2000prh.googlegroups.com>
On Apr 12, 11:46 pm, Barry Margolin <······@alum.mit.edu> wrote:
> In article
> <····································@q10g2000prf.googlegroups.com>,
>
>
>
>  ···········@gmail.com wrote:
> > On Apr 12, 11:06 pm, Pascal Bourguignon <····@informatimago.com>
> > wrote:
> > > ···········@gmail.com writes:
> > > > Kent Pitman suggested the following code, regarding a possible
> > > > implementation of an anonymous macro, in a previous post (http://
> > > > groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?
> > > > dmode=source):
>
> > > > (DEFMACRO META (&REST FORMS)
> > > >    (LET ((DO-IT (GENSYM "DO-IT")))
> > > >      `(MACROLET ((,DO-IT () ,@FORMS))
> > > >         (,DO-IT))))
>
> > > > but it seems to me that, according to the HyperSpec, this would not be
> > > > 100% safe. Quote:
>
> > > > "The macro-expansion functions defined by macrolet are defined in the
> > > > lexical environment in which the macrolet form appears. Declarations
> > > > and macrolet and symbol-macrolet definitions affect the local macro
> > > > definitions in a macrolet, but the consequences are undefined if the
> > > > local macro definitions reference any local variable or function
> > > > bindings that are visible in that lexical environment."
>
> > > > In this case the ,@forms would be the suspect.
>
> > > > More
> > > > here:http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html
>
> > > > Opinions?
>
> > > Why FORMS and not DO-IT?
> > > They've got equal status with respect to the macrolet form.
>
> > > (macroexpand '(meta `(progn ,@(loop :repeat 5 :collect '(print 'hi)))))
> > > --> (MACROLET ((#:DO-IT10523 NIL `(PROGN ,@(LOOP :REPEAT 5 :COLLECT '(PRINT
> > > 'HI)))))
> > >       (#:DO-IT10523)) ;
> > >     T
>
> > > Now the question is what could be wrong in this macrolet form?
> > > I see nothing wrong in it.
>
> > "... the consequences are undefined if the
> > local macro definitions reference any local variable or function
> > bindings that are visible in that lexical environment."
>
> > That is what appears to be wrong.
>
> You said you think ,@forms would be suspect, but it doesn't appear in
> the local macro definition.  It's in the original macro, but when that
> macro expands into a MACROLET it gets replaced with the forms.
>
> --
> Barry Margolin, ······@alum.mit.edu
> Arlington, MA
> *** PLEASE don't copy me on replies, I'll read them in the group ***

Absolutely right. Yes, I see. Thank you.
From: Pascal Bourguignon
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <87fxtq37zu.fsf@thalassa.informatimago.com>
···········@gmail.com writes:
>> Why FORMS and not DO-IT?
>> They've got equal status with respect to the macrolet form.
>>
>> (macroexpand '(meta `(progn ,@(loop :repeat 5 :collect '(print 'hi)))))
>> --> (MACROLET ((#:DO-IT10523 NIL `(PROGN ,@(LOOP :REPEAT 5 :COLLECT '(PRINT 'HI)))))
>>       (#:DO-IT10523)) ;
>>     T
>>
>> Now the question is what could be wrong in this macrolet form?
>> I see nothing wrong in it.
>>
>> --
>> __Pascal Bourguignon__                    http://www.informatimago.com/
>>
>> "Specifications are for the weak and timid!"
>
> "... the consequences are undefined if the
> local macro definitions reference any local variable or function
> bindings that are visible in that lexical environment."
>
> That is what appears to be wrong.

What local variable of function???


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
From: Alex Mizrahi
Subject: Re: MACROLET and lexical variables
Date: 
Message-ID: <4801f884$0$90264$14726298@news.sunsite.dk>
 rr> (DEFMACRO META (&REST FORMS)
 rr>    (LET ((DO-IT (GENSYM "DO-IT")))
 rr>      `(MACROLET ((,DO-IT () ,@FORMS))
 rr>         (,DO-IT))))

 rr> but it seems to me that, according to the HyperSpec, this would not be
 rr> 100% safe. Quote:

 rr> "The macro-expansion functions defined by macrolet are defined in the
 rr> lexical environment in which the macrolet form appears. Declarations
 rr> and macrolet and symbol-macrolet definitions affect the local macro
 rr> definitions in a macrolet, but the consequences are undefined if the
 rr> local macro definitions reference any local variable or function
 rr> bindings that are visible in that lexical environment."

 rr> In this case the ,@forms would be the suspect.
 rr> More here: 
http://www.lisp.org/HyperSpec/Body/speope_fletcm_scm_macrolet.html
 rr> Opinions?

there is an example on that page:

(defun foo (x flag)
   (macrolet ((fudge (z)
                 ;The parameters x and flag are not accessible
                 ; at this point; a reference to flag would be to
                 ; the global variable of that name.
                 ` (if flag (* ,z ,z) ,z)))
    ;The parameters x and flag are accessible here.
     (+ x
        (fudge x)
        (fudge (+ x 1)))))

can't use see it is _complety_ different case?