Fri Jun 20 12:06:22 CEST 2008

the meta namespace

i run into a problem with different instances of the target-word
structure. maybe the solution is to make sure badnop runs in a module

looks like the problem is with using the namespace anchor attached to
the module namespace.. maybe best to attach it to the repl's toplevel

There's still some confusion: if a module A is in namspace NS, and
module B is required, but B requires A, then A will be
re-instantiated, right? Unless NS is a module namespace.

Let's see, what's the difference between:

> (define ns (make-base-namespace))
> (dynamic-require "target/rep.ss" #f)
instantiating target/rep
> (namespace-require "target/rep.ss")
> (namespace-attach-module (current-namespace) "target/rep.ss" ns)
> (parameterize ((current-namespace ns)) (namespace-require "target/rep.ss"))

and doing this from within a module doesn't work...

An explanation: when a require form is evaluated inside a module, the
module registery of the required module is not the same as that of the
namespace in which it is required.

A toy example:

(module A racket/base (printf "instantiating A\n"))
(module B racket/base (require 'A) (printf "instantiating B\n"))

box> (require 'A)
instantiating A
box> (require 'B)
instantiating B


box> (require 'B)
instantiating A
instantiating B

so... A is not re-instantiated.. what am i doing wrong?

ok.. the namespace.ss code works just fine:

;; Create a namespace with shared and private module instances.
(define (shared/initial-namespace src-ns shared private)
  (let ((dst-ns (make-base-namespace)))

    ;; See PLT 4.0 guide, section 16.3
    ;; Reflection and Dynamic Evaluation -> Sharing Data and Code Across Namespaces
    (define (load-shared mod)
      (parameterize ((current-namespace src-ns))  ;; make sure it's there
        (dynamic-require mod #f)
        (namespace-require mod))

      (namespace-attach-module src-ns mod dst-ns) ;; get instance from here
      (parameterize ((current-namespace dst-ns))  ;; create bindings
        (namespace-require mod))

    (define (load-private mod)
      (parameterize ((current-namespace dst-ns))
        (dynamic-require mod #f)
        (namespace-require mod)))

    (for-each load-shared shared)
    (for-each load-private private)


The problem seems to be about other modules that are loaded into that
namespace. They seem to re-instantiate the the target/rep module.

Ok, it was really really stupid:

(namespace-require "pic18.ss")) ->  (namespace-require 'staapl/pic18))

Just a module name issue.