[plt-scheme] namespace-attach-module and sharing modules between evals
--- Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
> Hi everyone,
>
> The following three modules is a small test case I'm building to
> better understand namespace-attach-module:
>
>
>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (module brick mzscheme
> (define-struct brick (a b))
> (provide (struct brick (a b)))
> (printf "brick.ss is invoked~n"))
>
>
> (module evaluation mzscheme
> (provide (all-defined))
>
> (define (module-path->symbol module-path)
> ((current-module-name-resolver) module-path #f #f))
>
> (define (make-evaluation-namespace)
> (let ([ns (make-namespace)]
> [main-ns (current-namespace)])
> (parameterize ([current-namespace ns])
> (namespace-attach-module main-ns
> (module-path->symbol "brick.ss")
> ns)
> ns))))
>
>
>
> (module test-evaluation mzscheme
> (require "evaluation.ss"
> "brick.ss")
> (define my-ns (make-evaluation-namespace)))
>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
>
> Unfortunately, it doesn't work; when I invoke the test-evaluation
> module, I see the following:
>
>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> brick.ss is invoked
> evaluation.ss::323: namespace-attach-module: a different module
> with the same name is already in the destination namespace,
> for name: |,/home/dyoo/brick|
>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
You are using the current module name resolver to turn "brick.ss"
into a module name (symbol). I believe that in doing so you are
triggering the loading of the module into the current namespace (ns),
and so you aren't able to attach it from the original namespace
(main-ns).
Try moving the call to module-name->symbol outside of the
parameterize expression.
Ryan
> This disturbs me a lot, because I'm taking most of this from
> web-server; (lib "configuration.ss" "web-server") appears
> to do the same kind of tricks here in the-make-server-namespace,
> and I'm not yet seeing why what I'm doing here is different.
> I've tested this under both DrScheme and
> mzscheme 3.01.15-svn22may2006, as well as mzscheme 301-stable.
>
>
> Any help would be greatly appreciated. Thank you!
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>