[plt-scheme] Scope of eval?

From: Jakub Piotr Cłapa (jpc at pld-linux.org)
Date: Mon Oct 1 15:03:43 EDT 2007

Grant Rettke wrote:
> On 9/30/07, Jakub Piotr Cłapa <jpc at pld-linux.org> wrote:
> 
>> Carl Eastlund wrote:
> 
>>> Eval only works on global variables.  In your example, x is a field
>>> bound in a specific object.
> 
>> If you want to eval in some other context either wrap it with a lambda
>> and call the returned value or play with namespace-* functions.
> 
> How would I use lambda to go about getting the desired effect?

Sorry, this thing you are doing probably won't work with the lambda 
aproach. I was thinking about defining a lambda which will take the 
symbols you want to have bound inside the evaled code. Something like this.

(define user-code '(+ (* 2 (* x x)) (* 5 x)))

(let ([x 5]
       [y 10])
   ((eval `(lambda (x y) ,user-code)) x y))

This obviously won't work for set!.

-- 
regards,
Jakub Piotr Cłapa


Posted on the users mailing list.