<div dir="ltr">Glad to hear you got something working. I'm cc'ing the list again in case someone who knows more about the web-server/templates library has any suggestions.<div><br></div><div>Robby</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, May 15, 2013 at 10:37 AM, Matthew Butterick <span dir="ltr"><<a href="mailto:mb.list.acct@gmail.com" target="_blank">mb.list.acct@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Probably more products should have an FHQ (Frequently Hopeless Questions) in addition to an FAQ.<div><br></div><div>I'm making a web-page generator that uses include-template from web-server/templates. I need to set the template inputs & the template itself at runtime, and collect the output.</div>
<div><br></div><div>I tried doing it with module and module* but I didn't see how to make the data go round-trip. A submodule with include-template could require the needed data from the enclosing module, but then the enclosing module can't require the submodule to get the result, so ... ? I could well be overlooking an obvious technique.</div>
<div><br></div><div>My original solution was to write a new file and send it through the Racket executable as a system command. (This worked, slowly.) </div><div><br></div><div>So that's how I ended up using eval. Which does work, now that I've retooled how I set up the namespace.</div>
</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 14, 2013 at 5:13 PM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The short answer is that the top-level is hopeless, as Matthew has discussed at some length here and elsewhere. <div>
<br></div><div>If you really need to eval code, can you first put it into a module?</div>
<div><br>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, May 14, 2013 at 11:09 AM, Matthew Butterick <span dir="ltr"><<a href="mailto:mb.list.acct@gmail.com" target="_blank">mb.list.acct@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>Suppose x-is-foo.rkt is this:</div><div><br></div><div><div>(module x-is-foo racket</div>
<div> (define x 'foo)</div>
<div> (provide x))</div><div><br></div><div>If you open another file and try this:</div>
<div><div><br></div><div>(require "x-is-foo.rkt")</div><div>(define x 'bar)</div><div><br></div><div>You'lll get a "identifier already imported" error. OK, that much I understand.</div>
<div><br></div><div>Here's the question. When you do this:</div><div><br></div><div><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>This time, you get 'foo. Why 'foo? Why not another "identifier already imported" error?</div>
<div><br></div><div>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><br></div><div>It's not a sequencing issue, because if you swap the two lines:</div><div><br></div><div><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>You still get 'foo.</div>
</div><div><br></div><div>Only if you remove the require line:</div><div><br></div><div><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>Do you get 'bar.</div><div><br></div><div><br></div>
</div></div></div></div></div>
<br></div></div>____________________<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>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>