Fri Apr 4 12:27:26 EDT 2008
looks like i'm stuck at a fundamental misunderstanding.. each time
'require' is called, the RHS of define expressions is evaluated. so
ALL the expressions are instantiated! this happens EVERY TIME AGAIN
when code is required.
however, this process is fast if the code is already COMPILED.
how did i work around this with the ns hash before? it looked as if
there was only a single instance.. maybe because i was working in a
single module environment?
in the light of the re-definitions and parameters mentioned before,
what i'm trying to do doesn't really make sense: suppose i want a
PIC18 and PIC30 forth. if i want both of them in the same module,
parameters would be a good approach.
but having them in separate modules would work just as well. they
would represent different specialized instances of the core compiler,
but would have no sharing of data. they could be explicitly put in
different namespaces. in such an approach, modifying the
word-structures in-place is a perfectly legitimate approach.
the parameter words weren't for nothing however: they can still be
used for local parameterizations, like ";".
OK. 'compositions' and 'patterns' now will re-define words, with
'super' bound to the previous implementation.
i guess now it's time to see how to compute code instances?
i tried this:
tom@del:/tmp$ cat A.ss
(require "B.ss" "C.ss")
tom@del:/tmp$ cat B.ss
tom@del:/tmp$ cat C.ss
box> (require "A.ss")
box> (define NS (make-namespace))
box> (parameterize ((current-namespace NS)) (namespace-require "A.ss"))
so, what happens is: each toplevel require pulls in what is necessary,
but instantiates the phase 0 expressions only once. the same require
in the same namespace will not do anthing, but in a different
namespace it will instantiate again: values are not shared between
namespaces, but compiled expressions are shared (the global module
The manual has this to say:
In a top-level context, require instantiates modules (see Modules
and Module-Level Variables). In a module context, require visits
modules (see Module Phases). In both contexts, require introduces
bindings into a namespace or a module (see Introducing Bindings).
So what's the difference between 'instantiate' and 'visit'? Visit just
looks at the phase 0 names, and evaluates any phase 1 expressions, but
doesn't evaluate phase 0 expressions. Got it.
This brings new light to collecting code. All modules should require
the central code registry, which then defines a *code* variable. Got
every module's code annotated by its name too: this gives all the code
compiled + a possibility to take only what's necessary.