[R6RS] Chez modules question

dyb at cs.indiana.edu dyb
Tue Jan 18 16:28:45 EST 2005

> >> - How do the files or the modules within the files refer to each
> >>   other?
> Kent> By explicitly including them together or by loading or visiting files at
> Kent> compile time, either via external control (e.g., on the command line or
> Kent> with explicit loads prior to calling compile-file) or via eval-when forms.
> Kent> By "visiting a file" I mean calling "visit" on a compiled object file,
> Kent> which brings in its compile-time bindings only.
> If I have files A1.scm and A2.scm, both containing modules called A,
> and a file called B.scm that imports a module called A.  Presumably, I
> can compile these files separately and load them again later.  If I've
> compiled B.scm together with A1.scm, what happens if I later try to
> load the compiled file of A2.scm together with B.scm?

If the compiled version of A1 has not also been loaded, you'll get an
unbound variable error for any variable of A1's A referenced by B if a
reference to that variable is evaluated.  Each identifier exported by
a module is mapped in the compile-time environment to a gensym (with
globally unique name), so the run-time variables of A1's A are entirely
disjoint from the run-time variables of A2's A.

Here is your example reduced to actual code:

% echo '(module a (x) (define x 0))' > a1.ss
% echo '(module a (x) (define x 1))' > a2.ss
% echo '(define (f) (import a) x)' > b.ss
% echo '(compile-file "a1")' | scheme -q
compiling a1.ss with output to a1.so
% echo '(compile-file "a2")' | scheme -q
compiling a2.ss with output to a2.so
% echo '(visit "a1.so") (compile-file "b")' | scheme -q
compiling b.ss with output to b.so
% echo '(f)' | scheme -q a1.so b.so
% echo '(f)' | scheme -q a2.so b.so
Error: variable x is not bound.


More information about the R6RS mailing list