[plt-scheme] Using eval in modules

From: Mark Smithfield (m_smithfield at yahoo.com)
Date: Sat Jun 23 21:39:28 EDT 2007

 
> 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/


Posted on the users mailing list.