[plt-scheme] Question about eval and environments

From: Mike J. Bell (ckimyt at gmail.com)
Date: Thu Oct 25 13:50:49 EDT 2007

Ok, will do.

How about "in long?"  Why can't eval bind to an environment that encompasses
the lexical closure I made?

Mike

On 10/25/07, Chongkai Zhu <czhu at cs.utah.edu> wrote:
>
> Mike J. Bell wrote:
> > I don't think this is PLT specific, so I apologize if this should be
> > on a more general scheme list.
> >
> > I'm interested in adding a generic hook to evaluate a piece of code at
> > an arbitrary point in my program.  This would be useful for debugging
> > purposes.  For instance:
> >
> > (let ((x 5))
> >   ;(do a bunch of stuff with x)
> >   (write (eval (read))))
> >
> > Obviously this isn't very useful outside of a loop or other more
> > complicated idea, but this is just a toy to show the problem.  When
> > (read) runs, I would like to type in something like:
> >
> > (set! x 7)
> >
> > This doesn't work.  The error is that 'x' is unbound.  So I tried:
> > ...
> >   (write (eval (read) (interaction-environment))))
> >
> > and that didn't work either.  It seems like I can't get to the
> > environment that contains the lexical closure created by the initial
> > (let...).
> >
> > Is there any way around this?  I supposed I could write my own (mini)
> > version of eval, but that seems pretty extreme.  How can I get access
> > to the lexical environment at the point (eval) is executed so I can
> > inject arbitrary code?
>
> In short, you can't. So try some other way to do the debug, say using
> the debug tool.
>
> >
> > Thanks for any tips!!!
> >
> > Mike
> >
> > --
> > Mike J. Bell on gmail
> > ------------------------------------------------------------------------
> >
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
>


-- 
Mike J. Bell on gmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071025/099215f2/attachment.html>

Posted on the users mailing list.