[plt-scheme] Attaching uninstantiated modules

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jul 27 14:53:00 EDT 2002

> Hello. Thus spake mzscheme:
> Welcome to MzScheme version 200, Copyright (c) 1995-2002 PLT
> > (define ns1 (make-namespace))                         
> > (define ns2 (make-namespace))                         
> > (eval '(module foo mzscheme (provide bar) (define bar 42)) ns1)
> > (parameterize ((current-namespace ns2)) (namespace-attach-module ns1 'foo))
> namespace-attach-module: module not instantiated (in the source namespace): foo
> > (parameterize ((current-namespace ns1)) (namespace-require 'foo))
> > (parameterize ((current-namespace ns2)) (namespace-attach-module ns1 'foo))
> What's the problem here? Why couldn't an uninstantiated module be
> attached so that it would be instantiated by whichever namespace
> happened to require it first?

The notion of "attach" depends on having an instance.

If you wanted to just share the declaration of `m', then the
declaration can be evaluated separetly in each namespace --- there's no
difference at that level (but also no sharing of the variables within
the module).

I suppose we could introduce the concept of a module instance whose
body is not yet executed, and attaching such an instance would make
sense. But that's not much different than, say, attaching a normal
module instance whose body invokes a unit lazily.


Posted on the users mailing list.