[racket] help: how to make eval see local bindings?
On Mon, Jul 11, 2011 at 02:26:19PM +0200, Maurizio Giordano GMAIL wrote:
> 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.
I'm not sure what you're trying to do, but leaving out both the eval and the
quote would seem to be what you want:
(let ((x 1)
(f (lambda (y) (+ x y))))
(f 2))
I don't know how that relates to your macro.
-- hendrik