This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Dynamic scoping



> 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... :)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]