[plt-scheme] Using eval in modules

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sat Jun 23 22:44:16 EDT 2007

(interaction-environment) is not the lexical environment. It is the
top-level environment, which will contain only mzscheme primitives for
the program below.

When I run the code below, I get this:

  reference to undefined identifier: abc

As far as the original poster's question goes, there is no
"workaround", I don't believe. It works that way by design.

Robby

On 6/23/07, Mark Smithfield <m_smithfield at yahoo.com> wrote:
>
> > On Jun 23, 2007, at 8:56 AM, Jean-Pierre Lozi wrote:
> >
> > > Hi all,
> > >
> > > How can I use eval in a module definition? For
> > instance,
> > >
> > > (define (abc x)
> > >  (display "foo")
> > >  (newline))
> > >
> > > ((eval (string->symbol "abc")) 1)
> > >
> > > works, whereas
> > >
> > > (module foo mzxcheme
> > >  (define (abc x)
> > >   (display "foo")
> > >   (newline))
> > >
> > >   ((eval (string->symbol "abc")) 1))
> > >
> > > (require foo)
> > >
> > > doesn't. Eval appears too look for the abc
> > function in the global
> > > namespace. Does anyone know a workaround?
> > >
> > > Thanks,
>
> (eval) wants not just an expression but also an
> environment.
> (interaction-environment) is the local environment so
> far.
>
> (module foo mzscheme
>   (define (abc x)
>     (display "foo") (newline))
>
>   ((eval (string->symbol "abc")
> (interaction-environment)) 'ignore))
>
> (require foo)
>
> You will need to understand how environment impacts
> the use of eval.
>
>
>
>
> ____________________________________________________________________________________
> TV dinner still cooling?
> Check out "Tonight's Picks" on Yahoo! TV.
> http://tv.yahoo.com/
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.