In article <··············@individual.net>,
Pascal Costanza <··@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
From: Pascal Costanza
Subject: Re: Is it possible to implement augment-environment portably?
Date:
Message-ID: <4lj0srF24p0aU1@individual.net>
Ron Garret wrote:
> In article <··············@individual.net>,
> Pascal Costanza <··@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/