[racket] help: how to make eval see local bindings?

From: Maurizio Giordano GMAIL (maurizio.giorda at gmail.com)
Date: Mon Jul 11 08:26:19 EDT 2011

Hi to all schemers,

I know that "eval" evaluates the argument without 
visibility of the local environment where it is called.
so the following code has this error:

> (let ((x 1)) (eval '(+ x 1))
reference to undefined identifier: x

On contrary, if "x" is defined in the top environment, I have:

> (define x 2)
> (let ((x 1)) (eval '(+ x 1))
4

So the eval sees the global environment.

Can someone tell me if it possible to evaluate a 
quoted expression in such a way all local bindings
(the "let" bindings" are visible to the eval?

In my case I need to eval a quoted lambda which uses
variables that "should" bound in the local environment ...
this is the code:

> (let ((x 1) 
        (f (eval '(lambda (y) (+ x y)))))
    (f 2))
reference to undefined identifier: x

PS. my lambda is generated by a macro (define-syntax) ... 
this is why I use eval to generate the corresponding procedure.

TIA,

Maurizio Giordano




Posted on the users mailing list.