<div dir="ltr"><div style>Suppose x-is-foo.rkt is this:</div><div style><br></div><div style><div>(module x-is-foo racket</div><div> (define x 'foo)</div><div> (provide x))</div><div><br></div><div style>If you open another file and try this:</div>
<div style><div><br></div><div>(require "x-is-foo.rkt")</div><div>(define x 'bar)</div><div><br></div><div style>You'lll get a "identifier already imported" error. OK, that much I understand.</div>
<div style><br></div><div style>Here's the question. When you do this:</div><div style><br></div><div style><div>(parameterize ([current-namespace (make-base-empty-namespace)])</div><div> (namespace-require 'racket)</div>
<div> (namespace-require "x-is-foo.rkt")</div><div> (namespace-set-variable-value! 'x 'bar) </div><div> (eval '(print x) (current-namespace)))</div><div><br></div><div style>This time, you get 'foo. Why 'foo? Why not another "identifier already imported" error?</div>
<div style><br></div><div style>I assume I'm missing a subtlety of how the namespace environment is different. But according to the docs, both namespace-require and namespace-set-variable-value! affect the top-level environment of the namespace. So I don't see why the require is silently overriding the set-variable-value, rather than causing a conflict.</div>
<div style><br></div><div style>It's not a sequencing issue, because if you swap the two lines:</div><div style><br></div><div style><div>(parameterize ([current-namespace (make-base-empty-namespace)])</div><div> (namespace-require 'racket)</div>
<div> (namespace-set-variable-value! 'x 'bar) </div><div> (namespace-require "x-is-foo.rkt")</div><div> (eval '(print x) (current-namespace)))</div><div><br></div><div style>You still get 'foo.</div>
</div><div style><br></div><div style>Only if you remove the require line:</div><div style><br></div><div style><div>(parameterize ([current-namespace (make-base-empty-namespace)])</div><div> (namespace-require 'racket)</div>
<div> (namespace-set-variable-value! 'x 'bar) <br></div><div> (eval '(print x) (current-namespace)))</div><div><br></div><div style>Do you get 'bar.</div><div style><br></div><div style><br></div>
</div></div></div></div></div>