[plt-scheme] Exposing non-exported module variable bindings.

From: Richard C. Cobbe (cobbe at ccs.neu.edu)
Date: Tue Dec 16 21:31:55 EST 2003

Lo, on Sunday, December 14, Raymond Racine did write:

> Here's a little trick to write SchemeUnit tests in a separate file which
> allows testing a modules exported and unexported variable bindings.  The
> module/expose macro exposes simple non-provided variable bindings for
> testing.

That's something I've been looking for for a long time.  Thanks for
posting it!


> (define-syntax module/expose
>   (syntax-rules ()
>     ((_ mod (id1 ...))
>      (begin
>        (require mod)
>        (define-values (id1 ...)
>          (let ([ns (module->namespace mod)])
>            (parameterize ([current-namespace ns])
>              (values 
>               (namespace-variable-value 'id1 #t void) ...))))))))
> (module/expose "mod.scm" (a b)) ;; expose non-provided a and b bindings.

Unfortunately, this only seems to work if mod is a string; forms like
(lib "foo.ss" "bar") generate unbound identifier errors for lib.  Is
there an easy way to get this case to work as well?

Even with that problem, though, this goes a long way towards making
testing with modules much easier.  Thanks again!


Posted on the users mailing list.