[plt-scheme] Re: eval question

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Wed Jun 29 13:11:02 EDT 2005

Sorry about the late response.  Answers below.

--- "Arend P. van der Veen" <apvanderveen at att.net> wrote:

> Including a require statements would be very beneficial
> in my case.
> Following is the code segment that I came up with to
> implement this:
> (require (lib "string.ss"))
> (let ((my-string "(begin (require (lib \"utilities.ss\"
> \"srs\")) 
> (lambda () (yes-no-list)))"))
>    (let ((my-procedure (eval-string my-string)))
>      (printf "~a\n" (my-procedure))))
> yes-no-list is a procedure defined in utilities.ss (in
> srs).  Is this 
> correct or is there a better way to implement this.

That will certainly work, but it has the disadvantage that
my-string is evaluated in the same environment as the code
that calls eval.  This could lead to strange bugs if
my-procedure manipulates anything in the environment.  To
avoid this you should:

1. Create a new namespace  (make-namespace 'initial)

2. Require any modules you want to evaled code to have
access to using namespace-require

3. Call eval when you have parameterised current-namespace
to the namespace created above.

I've updated the recipe to include this:


(define new-namespace (make-namespace 'initial))

(parameterize ((current-namespace new-namespace))
  (namespace-require '(file "my-module.ss"))
  (eval untrusted-code))

The remaining issue is sharing of modules between
namespaces.  Do you want the modules in the new namespace
to be references to the modules in the current namespace
(i.e the same), or new invocations.  Probably you want them
to be the same.  For this you want namespace-attach-module.
 I don't have time right now to write this us :-(

You might find my namespace package in Planet to be useful;
on the other hand, I can't remember if I 1) updated it to
299 and 2) fixed the packaging bug.  If I didn't do either,
you might find it very unuseful.


Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Discover Yahoo! 
Find restaurants, movies, travel and more fun for the weekend. Check it out! 

Posted on the users mailing list.