[plt-scheme] Problems with eval

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Thu Jul 3 15:42:38 EDT 2008

The (namespace-require 'scheme/base) worked fine.  Is there any
advantage/disadvantage to using the private namespace as Eli suggested?

On Thu, Jul 3, 2008 at 1:19 PM, Eli Barzilay <eli at barzilay.org> wrote:

> On Jul  3, Robby Findler wrote:
> > This is not a bug.
> >
> > The top-level namespace (ie the part of the namespace that deals
> > with code outside modules) for the module language does not have any
> > bindings. You have to initialize it with some if you want to use
> > them.
> >
> > It would be better to avoid eval (as has been mentioned a few times
> > on this list) but on the assumption that eval is truely necessary,
> > try this:
> >
> >   #lang scheme
> >   (namespace-require 'scheme/base)
> >   (eval '((lambda (x) x) 1))
> >
> > Without the second line, the third one won't work, but with it, it
> > does.
>
> You can also use a private namespace
>
>  #lang scheme
>  (define ns (make-base-namespace))
>  (eval '((lambda (x) x) 1) ns)
>
> or even better, you can use the namespace of the current module:
>
>  #lang scheme
>  (define-namespace-anchor anchor)
>  (eval '((lambda (x) x) 1) (namespace-anchor->namespace anchor))
>
> and you can even do this now:
>
>  #lang scheme
>  (define-namespace-anchor anchor)
>  (define c 1)
>  (eval '((lambda (x) x) c) (namespace-anchor->namespace anchor))
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                  http://www.barzilay.org/                 Maze is Life!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080703/f51b982c/attachment.html>

Posted on the users mailing list.