[plt-scheme] Differences in "load" from within Dr. Scheme vs. from compiled code?
I'm having problems accessing binding in the namespace of a module from
an externally loaded file. I'm wondering if anyone can point out where
I'm going wrong.
I'm loading an external file using (load ...) from within a module.
Within the external file, I'm calling a function in the module to set
the value of a variable, something like this:
In environment.scm:
(module environment mzscheme
(require (lib "file.ss"))
; set a flag
(define flag #f)
(provide set-flag!)
(define (set-flag! in-flag)
(display "set-flag! called")
(newline)
(set! flag in-flag))
; load external file
(define (loadit)
(load "external.scm")
(display "flag: ")
(display flag)
(newline)
)
; start
(provide run)
(define (run)
(loadit)
)
)
In external.scm:
(require "environment.scm")
; set flag
(display "before call")
(newline)
(set-flag! #t)
All of this is called from another file, main.scm:
(module main mzscheme
(require "environment.scm")
(run)
)
This works fine within Dr. Scheme, ie. the flag is set to #t. However,
when I compile the module and then run the resulting .exe file, the
value of the variable seems to retain its initial value (its value is
printed as #f), even though the function call was successful.
Note that to make this work, I had to require the "environment" module
within the external file, and had to require the "environment" module
from another module (main). If I didn't require the "environment" module
in external.scm, then the external file couldn't access the set-flag!
function, and if I just compiled environment.scm to a .exe, then the
"environment" module was executed twice, presumably once as
"environment" and once and "environment.scm"...
I'm guessing that, for some reason, in the compiled version the external
file creates a separate namespace for the module when its loaded. Does
this sound possible? Anyone know how to avoid this, ie. to make the
bindings in the module namespace available to the loaded file? (Perhaps
I'm going about this completely the wrong way?)
thanks,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070516/7bfc340f/attachment.html>