This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
Re: Dynamic scoping
- To: David Lutterkort <lutter@cise.ufl.edu>
- Subject: Re: Dynamic scoping
- From: Jim Blandy <jimb@red-bean.com>
- Date: 19 Jul 1999 17:09:54 -0500
- Cc: guile@cygnus.com
- References: <m2wvwuaf4i.fsf@amberjack.cise.ufl.edu>
> With Jim Blandy's environment proposal that Jost is implementing it looks
> like it would be almost possible to implement some kind of dynamic
> scopes. What I am interested in is the following scenario: I want to write
> one function that constructs and returns an environment which then can be
> passed to other functions so they can use that when evaluating some
> expressions, like
>
> (define (make-stuff) (let ((env (make-finite-environment)) ... env)))
>
> (define (use-stuff stuff-env . other-args)
> ...
> (with-environment stuff-env
> ... access things by first looking into stuff-env and then
> into the surrounding lexical scope ...))
>
> The only thing that's missing in the current environment implementation is
> a with-environment macro. Could make-eval-environment be used for this ?
> Would something like
>
> (defmacro with-environment (env . body)
> `(eval (begin ,@body) (make-eval-environment ,env (the-environment))))
>
> do the trick or is there a better / more elegant / no solution to this
> problem ?
Hmm, the semantics are right, but you're invoking eval every time the
expression is evaluated. I guess there's no help for it, though; env
might contain macro definitions... :)