<!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 &quot;load&quot; 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 &#8230;) 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">&nbsp; (require (lib &quot;file.ss&quot;))</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; ; set a flag</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (define flag #f)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (provide set-flag!)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (define (set-flag! in-flag)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (display &quot;set-flag! called&quot;)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (newline)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (set! flag in-flag))</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; ; load external file</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (define (loadit)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (load &quot;external.scm&quot;)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (display &quot;flag: &quot;)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (display flag)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newline)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; )</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&nbsp; ; start</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (provide run)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (define (run)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; (loadit)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; )</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 &quot;environment.scm&quot;)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">; set flag</FONT>

<BR><FONT SIZE=2 FACE="Arial">(display &quot;before call&quot;)</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">&nbsp; (require &quot;environment.scm&quot;)</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; (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 &quot;environment&quot; module within the external file, and had to require the &quot;environment&quot; module from another module (main). If I didn&#8217;t require the &quot;environment&quot; 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 &quot;environment&quot; module was executed twice, presumably once as &quot;environment&quot; and once and &quot;environment.scm&quot;... </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>