[plt-scheme] eval and namespaces question

From: Doug Orleans (dougo at ccs.neu.edu)
Date: Mon Dec 16 15:54:22 EST 2002

John W. Small writes:
 > 
 > I'd like to define values within a module context using eval:
 > 
 >     (module foo mzscheme
 >       (eval '(define x 1)))
 > 
 > and require them in another module:
 > 
 >     (module bar mzscheme
 >       (require foo)
 >       x       ; error: expand:  unbound variable x
 >     )

This may be a silly answer, but how about:

  (eval '(module foo mzscheme
           (define x 1)
           (provide x)))

By the way, I think expressions in a module body are only evaluated
for side-effect, so just putting `x' in the body won't do anything.
But you can re-provide its value:

  (module bar mzscheme
    (require foo)
    (define y x)
    (provide y))

  > (require bar)
  > y
  1

--dougo at ccs.neu.edu


Posted on the users mailing list.