[plt-scheme] Question about eval and environments

From: Mike J. Bell (ckimyt at gmail.com)
Date: Thu Oct 25 12:03:25 EDT 2007

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?

Thanks for any tips!!!


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

Posted on the users mailing list.