<div dir="ltr"><div><div>Jos,<br><br></div>When you use make-base-empty-namespace, you get a namespace that shares the current instantiation of racket/base and nothing else. When you import racket using namespace-require, the result is a namespace that shares the original racket/base but has a fresh copy of everything else from racket. Since add1 is in racket/base, you will always get the same add1 back from this process. Since force is in racket/promise, you will always get a fresh force back from this process. If you want a fresh result every time, you need to start from a purely empty namespace that doesn't even contain racket/base. If you want an identical result every time, you need to share a single instance of all of racket rather than creating a new namespace.<br>
<br>All of this behavior is necessary for the Racket module system to work -- it needs to be possible to share instances sometimes and create fresh ones others, so when using namespaces and dynamic modules, one always has to be careful about this. I don't know of any metaphorical magic wand to wave to make it easy "most of the time", although of course any suggestions are welcome. And I'm sorry if you're mired in it, I know I've struggled with it rather bitterly more than once.<br>
<br></div><div>When I try to repeat this using make-empty-namespace to get a fresh result every time, I get an error about an unknown module named #%builtin, so I don't know what needs to be done to make this work. Still, in principle it should be doable.<br>
</div><div><br></div>--Carl<br><br><div class="gmail_extra"><div class="gmail_quote">On Sun, May 26, 2013 at 1:43 PM, Jos Koot <span dir="ltr"><<a href="mailto:jos.koot@gmail.com" target="_blank">jos.koot@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div>
<div>
<div><font face="Courier New"><font><span>#|
Consider: |#</span></font></font></div>
<div><font face="Courier New"><font><span></span></font></font> </div>
<div><font face="Courier New"><font><span></span>#lang racket</font></font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">(define (get-from-fresh-namespace
var)<br> (let ((namespace (make-base-empty-namespace)))<br>
(parameterize ((current-namespace namespace))<br> (namespace-require
'racket)<br> (namespace-variable-value var #t (λ ()
'error)))))</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">(eq?<br> (get-from-fresh-namespace
'add1)<br> (get-from-fresh-namespace 'add1)) ; -> #t</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">(eq?<br> (get-from-fresh-namespace
'force)<br> (get-from-fresh-namespace 'force)) ; -> #f</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New"><font>#|<br>It is clear to me why the last
form produces #f. Procedure force is a predicate of a struct and is exported by
module .../collects/racket/promise.rkt. For each fresh empty base-namespace the
form (namespace-require 'racket) uses a distinct instance of this module. Each
instance defines the promise-struct freshly and provides distinct variable- and
syntax-bindings related to promises.<span> Is my
observation correct?</span></font></font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">It is little bit confusing that procedure
get-from-fresh-namespace, when called with the same variable-name, in some cases
returns identical values and in other<span>s</span>
does not.</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">I think it is not easy to make Racket such
as to <span>make it</span> procedure
get-from-fresh-namespace always to return distinct objects (not eq?) or always
to return identical objects (eq?) when called with the same
variable-name.</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">I know, I am comparing procedures, but
as</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">|# (let ((a add1)) (eq? a add1))
#|</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New">is guaranteed to return #t, I wonder what
you folks think about to make modules such as always provide the same
instance <span>of a module </span>when
required<span> within the same Racket or DrRacket
session</span>. Is it possible? Is it desirable?<span>
What when a module produces side effects (e.g. displayed
output)?</span><br>|#</font></div>
<div><font face="Courier New"></font> </div>
<div><font face="Courier New"></font> </div></div></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div></div>