Is it possible to implement augment-environment portably?

  • Follow


If I do this:

(defmacro current-env (&environment env) env)

then I can capture a "macro closure" that allows me to expand macros 
defined by macrolet outside the lexical scope of that macrolet, e.g.:

(setf e (macrolet ((foo (x) `(cons ',x ',x))) (current-env)))
(macroexpand '(foo baz) e)  --> (CONS 'BAZ 'BAZ)

Is there any way to portably augment one of these lexical environment 
objects with additional definitions?  I'd like to be able to do 
something like:

(with-lexical-environment e
  (macrolet ((baz () (foo 'snoz))
    (current-env)))

and get an environment where (baz) expands to (cons 'snoz 'snoz).

Is that possible in portable CL?

rg
0
Reply rNOSPAMon (1856) 8/28/2006 6:59:06 PM

Ron Garret <rNOSPAMon@flownet.com> wrote:

> If I do this:
> 
> (defmacro current-env (&environment env) env)
> 
> then I can capture a "macro closure" 

No, you cannot (portably) capture the environment.  The object to which
ENV is bound has dynamic extent.  See 3.4.4:

<URL:http://www.lispworks.com/documentation/HyperSpec/Body/03_dd.htm>

> Is there any way to portably augment one of these lexical environment
> objects with additional definitions?

I don't think so.  Isn't that the point of Franz's/Duane Rettig's
environment access proposal (and in the case of ACL, implementation)?

> I'd like to be able to do something like:
> 
> (with-lexical-environment e
>   (macrolet ((baz () (foo 'snoz))
>     (current-env)))
> 
> and get an environment where (baz) expands to (cons 'snoz 'snoz).
> 
> Is that possible in portable CL?

I believe not.

-- 
Duncan Harvey
0
Reply usenet-2006-04 (18) 8/28/2006 7:33:32 PM


In article <1hksrfp.k53ycv1dmsq0uN%usenet-2006-04@abbrvtd.org.uk>,
 usenet-2006-04@abbrvtd.org.uk (Duncan Harvey) wrote:

> Ron Garret <rNOSPAMon@flownet.com> wrote:
> 
> > If I do this:
> > 
> > (defmacro current-env (&environment env) env)
> > 
> > then I can capture a "macro closure" 
> 
> No, you cannot (portably) capture the environment.  The object to which
> ENV is bound has dynamic extent.  See 3.4.4:
> 
> <URL:http://www.lispworks.com/documentation/HyperSpec/Body/03_dd.htm>

Oh.  Bummer.

rg
0
Reply rNOSPAMon (1856) 8/28/2006 7:47:19 PM

Ron Garret <rNOSPAMon@flownet.com> wrote:

> In article <1hksrfp.k53ycv1dmsq0uN%usenet-2006-04@abbrvtd.org.uk>,
>  usenet-2006-04@abbrvtd.org.uk (Duncan Harvey) wrote:
> 
> > Ron Garret <rNOSPAMon@flownet.com> wrote:
> > 
> > > If I do this:
> > > 
> > > (defmacro current-env (&environment env) env)
> > > 
> > > then I can capture a "macro closure" 
> > 
> > No, you cannot (portably) capture the environment.  The object to which
> > ENV is bound has dynamic extent.  See 3.4.4:
> > 
> > <URL:http://www.lispworks.com/documentation/HyperSpec/Body/03_dd.htm>
> 
> Oh.  Bummer.

If you're interested in AUGMENT-ENVIRONMENT capabilities, could you not
write as much of Environment Access-style as you need specifically for
the implementations you want?  Thereby creating a portability layer for
yourself.  If the implementations you use expose the underlying
functionality, albeit idiosyncratically, it might be easier than
attempting to code it portably (had that been possible).

OTOH if you you actually wanted to capture these kinds of environment
indefinitely, then, yeah, bummer.

-- 
Duncan Harvey
0
Reply usenet-2006-04 (18) 8/28/2006 8:42:22 PM

Ron Garret <rNOSPAMon@flownet.com> wrote:

> In article <1hksrfp.k53ycv1dmsq0uN%usenet-2006-04@abbrvtd.org.uk>,
>  usenet-2006-04@abbrvtd.org.uk (Duncan Harvey) wrote:
> 
> > Ron Garret <rNOSPAMon@flownet.com> wrote:
> > 
> > > If I do this:
> > > 
> > > (defmacro current-env (&environment env) env)
> > > 
> > > then I can capture a "macro closure" 
> > 
> > No, you cannot (portably) capture the environment.  The object to which
> > ENV is bound has dynamic extent.  See 3.4.4:
> > 
> > <URL:http://www.lispworks.com/documentation/HyperSpec/Body/03_dd.htm>
> 
> Oh.  Bummer.

If you're interested in AUGMENT-ENVIRONMENT capabilities, could you not
write as much of Environment Access as you need specifically for the
implementations you want?  Thereby creating a portability layer for
yourself.  If the implementations you use expose the underlying
functionality, albeit idiosyncratically, it might be easier than
attempting to code it portably (had that been possible).

OTOH if you you actually wanted to capture these kinds of environment
indefinitely, then, yeah, bummer.

-- 
Duncan Harvey
0
Reply usenet-2006-04 (18) 8/28/2006 8:53:18 PM

In article <1hksssh.1tqvj3z1fpn8owN%usenet-2006-04@abbrvtd.org.uk>,
 usenet-2006-04@abbrvtd.org.uk (Duncan Harvey) wrote:

> Ron Garret <rNOSPAMon@flownet.com> wrote:
> 
> > In article <1hksrfp.k53ycv1dmsq0uN%usenet-2006-04@abbrvtd.org.uk>,
> >  usenet-2006-04@abbrvtd.org.uk (Duncan Harvey) wrote:
> > 
> > > Ron Garret <rNOSPAMon@flownet.com> wrote:
> > > 
> > > > If I do this:
> > > > 
> > > > (defmacro current-env (&environment env) env)
> > > > 
> > > > then I can capture a "macro closure" 
> > > 
> > > No, you cannot (portably) capture the environment.  The object to which
> > > ENV is bound has dynamic extent.  See 3.4.4:
> > > 
> > > <URL:http://www.lispworks.com/documentation/HyperSpec/Body/03_dd.htm>
> > 
> > Oh.  Bummer.
> 
> If you're interested in AUGMENT-ENVIRONMENT capabilities, could you not
> write as much of Environment Access-style as you need specifically for
> the implementations you want?

Yes, I could do that, but I was hoping I wouldn't have to.

rg
0
Reply rNOSPAMon (1856) 8/28/2006 9:09:31 PM

Ron Garret wrote:
> If I do this:
> 
> (defmacro current-env (&environment env) env)
> 
> then I can capture a "macro closure" that allows me to expand macros 
> defined by macrolet outside the lexical scope of that macrolet, e.g.:
> 
> (setf e (macrolet ((foo (x) `(cons ',x ',x))) (current-env)))
> (macroexpand '(foo baz) e)  --> (CONS 'BAZ 'BAZ)
> 
> Is there any way to portably augment one of these lexical environment 
> objects with additional definitions?  I'd like to be able to do 
> something like:
> 
> (with-lexical-environment e
>   (macrolet ((baz () (foo 'snoz))
>     (current-env)))
> 
> and get an environment where (baz) expands to (cons 'snoz 'snoz).
> 
> Is that possible in portable CL?

Yes, it is, but it's not straightforward. I have an implementation (or 
better: something very close), and I hope I will be able to describe it 
soon. (Waiting for the ILC CfP...)


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
0
Reply pc56 (3896) 8/28/2006 9:57:31 PM

In article <4lh76bF1uoi2U1@individual.net>,
 Pascal Costanza <pc@p-cos.net> wrote:

> Ron Garret wrote:
> > If I do this:
> > 
> > (defmacro current-env (&environment env) env)
> > 
> > then I can capture a "macro closure" that allows me to expand macros 
> > defined by macrolet outside the lexical scope of that macrolet, e.g.:
> > 
> > (setf e (macrolet ((foo (x) `(cons ',x ',x))) (current-env)))
> > (macroexpand '(foo baz) e)  --> (CONS 'BAZ 'BAZ)
> > 
> > Is there any way to portably augment one of these lexical environment 
> > objects with additional definitions?  I'd like to be able to do 
> > something like:
> > 
> > (with-lexical-environment e
> >   (macrolet ((baz () (foo 'snoz))
> >     (current-env)))
> > 
> > and get an environment where (baz) expands to (cons 'snoz 'snoz).
> > 
> > Is that possible in portable CL?
> 
> Yes, it is, but it's not straightforward. I have an implementation (or 
> better: something very close), and I hope I will be able to describe it 
> soon. (Waiting for the ILC CfP...)
> 
> 
> Pascal

I know you have an approach where you shadow macrolet and maintain a 
user-accessible lexical environment in parallel with the one the system 
keeps.  But I was hoping not to have to reinvent that wheel (though I 
suppose if you're doing it for me that's good enough for my purposes ;-)

BTW, have you had a chance to look at the lexicon code?

rg
0
Reply rNOSPAMon (1856) 8/28/2006 11:06:29 PM

Ron Garret wrote:
> In article <4lh76bF1uoi2U1@individual.net>,
>  Pascal Costanza <pc@p-cos.net> wrote:
> 
>> Ron Garret wrote:
>>> If I do this:
>>>
>>> (defmacro current-env (&environment env) env)
>>>
>>> then I can capture a "macro closure" that allows me to expand macros 
>>> defined by macrolet outside the lexical scope of that macrolet, e.g.:
>>>
>>> (setf e (macrolet ((foo (x) `(cons ',x ',x))) (current-env)))
>>> (macroexpand '(foo baz) e)  --> (CONS 'BAZ 'BAZ)
>>>
>>> Is there any way to portably augment one of these lexical environment 
>>> objects with additional definitions?  I'd like to be able to do 
>>> something like:
>>>
>>> (with-lexical-environment e
>>>   (macrolet ((baz () (foo 'snoz))
>>>     (current-env)))
>>>
>>> and get an environment where (baz) expands to (cons 'snoz 'snoz).
>>>
>>> Is that possible in portable CL?
>> Yes, it is, but it's not straightforward. I have an implementation (or 
>> better: something very close), and I hope I will be able to describe it 
>> soon. (Waiting for the ILC CfP...)
>>
>>
>> Pascal
> 
> I know you have an approach where you shadow macrolet and maintain a 
> user-accessible lexical environment in parallel with the one the system 
> keeps.  But I was hoping not to have to reinvent that wheel (though I 
> suppose if you're doing it for me that's good enough for my purposes ;-)

Well, I am not going the whole way, but maybe my code can be used as a 
starting point.

> BTW, have you had a chance to look at the lexicon code?

No, haven't found the time.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
0
Reply pc56 (3896) 8/29/2006 2:22:19 PM

8 Replies
32 Views

(page loaded in 0.083 seconds)

Similiar Articles:













7/19/2012 8:54:34 PM


Reply: