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

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Mon Jul 11 10:12:52 EDT 2011

I'd like to add a +1 to the original question. If I can get eval to see local bindings, I can write a gdb-like debugger for Racket using call/cc, read and eval.
-Ian
----- Original Message -----
From: "Hendrik Boom" <hendrik at topoi.pooq.com>
To: users at racket-lang.org
Sent: Monday, July 11, 2011 9:02:08 AM GMT -05:00 US/Canada Eastern
Subject: Re: [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
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.