<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>Differences in "load" from within Dr. Scheme vs. from compiled code?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">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.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">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:</FONT></P>
<P><FONT SIZE=2 FACE="Arial">In environment.scm:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">(module environment mzscheme</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (require (lib "file.ss"))</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> ; set a flag</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (define flag #f)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (provide set-flag!)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (define (set-flag! in-flag)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (display "set-flag! called")</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (newline)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (set! flag in-flag))</FONT>
<BR><FONT SIZE=2 FACE="Arial"> </FONT>
<BR><FONT SIZE=2 FACE="Arial"> ; load external file</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (define (loadit)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (load "external.scm")</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (display "flag: ")</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (display flag)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (newline)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> )</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> ; start</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (provide run)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (define (run)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (loadit)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> )</FONT>
<BR><FONT SIZE=2 FACE="Arial">)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">In external.scm:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">(require "environment.scm")</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">; set flag</FONT>
<BR><FONT SIZE=2 FACE="Arial">(display "before call")</FONT>
<BR><FONT SIZE=2 FACE="Arial">(newline)</FONT>
<BR><FONT SIZE=2 FACE="Arial">(set-flag! #t)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">All of this is called from another file, main.scm:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">(module main mzscheme</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (require "environment.scm")</FONT>
<BR><FONT SIZE=2 FACE="Arial"> (run)</FONT>
<BR><FONT SIZE=2 FACE="Arial">)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">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.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">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"... </FONT></P>
<P><FONT SIZE=2 FACE="Arial">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?)</FONT></P>
<P><FONT SIZE=2 FACE="Arial">thanks,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Alex</FONT>
</P>
</BODY>
</HTML>