<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">The syntax of `enter!' is supposed to be like `require', where the<br>
</span><span style="font-family:arial,sans-serif;font-size:13px">module name is not quoted</span></blockquote><div><br></div><div style>OK, I see what you're saying. And yes, the enter! / require connection is noted in the docs. </div>
<div style><br></div><div style>As a reader of docs, what trips me up here is that the docs for enter! and require both refer to a module-path, but they will not necessarily take as input something that returns #t for module-path?, for instance:</div>
<div style><br></div><div style><div><div>(require "filename.rkt") ; works</div></div><div><br></div><div>(define name "filename.rkt")</div><div>(module-path? name) ; returns #t</div><div>(require name) ; doesn't work</div>
<div><br></div><div style>However, dynamic-require works differently:</div><div style><br></div><div style><div>(define name "filename.rkt")</div><div>(module-path? name) ; returns #t</div><div>(dynamic-require name 'foo) ;works</div>
</div><div style><br></div><div style>I notice that dynamic-require uses the module-path? contract, and enter! and require apparently do not. So OK, I guess that's why they can be more restrictive. But then when I look up the meaning of module-path?, it says:</div>
<div style><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style><div style><div style>Returns #t if v corresponds to a datum that <b>matches the grammar for module-path for require</b>, #f otherwise.</div>
</div></div></blockquote><div style><div style><div><br></div><div style>That is, module-path? seems to be defined in terms of what require will accept, but in practice module-path? accepts more than require will. Which, if true, is strange.</div>
<div style><br></div></div></div><div style><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Apr 28, 2013 at 6:11 AM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The syntax of `enter!' is supposed to be like `require', where the<br>
module name is not quoted. If you remove the quote, then something like<br>
<br>
(enter! file/gif)<br>
<br>
doesn't work.<br>
<br>
<br>
It would make sense to move the transitive module-reloading part of<br>
`enter!' to a a new module and provide a `dynamic-re-require' function<br>
that's similar to `do-enter!' --- and that would more directly be what<br>
you want, I think. I'll look into that.<br>
<div class=""><div class="h5"><br>
<br>
At Sun, 28 Apr 2013 00:09:13 -0700, Matthew Butterick wrote:<br>
> Thanks, I'll try that. However, I still think there might be a bug in<br>
> racket/enter.rkt. Currently lines 10-11 look like this:<br>
><br>
> [(enter! mod flag ...) (andmap keyword? (syntax->datum #'(flag ...)))<br>
> #'(do-enter! 'mod '(flag ...))]<br>
><br>
> But when I remove the quoting from mod in line 11, like so …<br>
><br>
> [(enter! mod flag ...) (andmap keyword? (syntax->datum #'(flag ...)))<br>
> #'(do-enter! mod '(flag ...))]<br>
><br>
> Then (enter! module-name-variable) works as hoped, and (enter!<br>
> "module-name-string.rkt") still works too.<br>
><br>
> Making it work proves nothing ;) I will file a bug report.<br>
><br>
> Matthew Butterick<br>
><br>
><br>
><br>
> On Sat, Apr 27, 2013 at 7:17 PM, Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>> wrote:<br>
><br>
> > I think you probably want to create a new namespace for each<br>
> > instantiation of the Scribble module, and attach Scribble (or whatever<br>
> > modules you want to stay the same across runs) to the namespace before<br>
> > `dynamic-require'ing the module in the new namespace:<br>
> ><br>
> > #lang racket/base<br>
> > (require scribble/base)<br>
> ><br>
> > (define (re-run module-path)<br>
> > (define ns (make-base-namespace))<br>
> > (namespace-attach-module (current-namespace) 'scribble/base)<br>
> > (parameterize ([current-namespace ns])<br>
> > (dynamic-require module-path #f)))<br>
> ><br>
> ><br>
> > At Sat, 27 Apr 2013 19:08:53 -0700, Matthew Butterick wrote:<br>
> > > OK, so the proposed solution failed once I tried to pass in the module<br>
> > name<br>
> > > as a variable. Even though enter! claims to take a module-path as an<br>
> > > argument, this will not work:<br>
> > ><br>
> > > (define name "module.rkt")<br>
> > > (module-path? name) ; reports #t<br>
> > > (enter! name) ; error: collection "name" not found<br>
> > ><br>
> > > enter! is treating "name" as a module path instead of resolving it as a<br>
> > > defined term. What I can't tell is whether this is mandatory behavior for<br>
> > > enter!, or if it's a bug in the enter! macro. (I did look at enter.rkt,<br>
> > but<br>
> > > this week, it's over my head.)<br>
> > ><br>
> > > Matthew Butterick<br>
> > ><br>
> > ><br>
> > > On Sat, Apr 27, 2013 at 6:16 PM, Matthew Butterick<br>
> > > <<a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a>>wrote:<br>
> > ><br>
> > > > Aha, combining enter! with dynamic-require seems to do the trick:<br>
> > > ><br>
> > > > (define (route req)<br>
> > > > (enter! "module.rkt")<br>
> > > > (define foo (dynamic-require "module.rkt" 'foo))<br>
> > > > (response/xexpr `(p ,(format "~a" foo))))<br>
> > > ><br>
> > > > Once this route is running in the web server, I can make changes to<br>
> > > > module.rkt, then click reload in the browser, and the changes will<br>
> > appear<br>
> > > > in the browser.<br>
> > > ><br>
> > > > If this is a terrible idea let me know, otherwise I'll consider this<br>
> > > > solved.<br>
> > > ><br>
> > > ><br>
> > > > On Sat, Apr 27, 2013 at 9:56 AM, Matthew Butterick <<br>
> > <a href="mailto:mb.list.acct@gmail.com">mb.list.acct@gmail.com</a><br>
> > > > > wrote:<br>
> > > ><br>
> > > >> I'm building a website using Scribble as the source format. As a<br>
> > > >> development tool, I've built a web server in Python that lets me view<br>
> > all<br>
> > > >> my Scribble source files and look at them in different states of<br>
> > > >> processing. To view the results of the Scribble files, the Python<br>
> > server<br>
> > > >> just sends the files to Racket via a system command (os.Popen) and<br>
> > reads<br>
> > > >> the result. This works but it's slow, because it has to launch a new<br>
> > > >> Racket thread for every request.<br>
> > > >><br>
> > > >> I thought I could speed things up by rewriting the development web<br>
> > server<br>
> > > >> in Racket. But having tried a few approaches, I'm not sure how to<br>
> > duplicate<br>
> > > >> this functionality within a Racket web servlet:<br>
> > > >><br>
> > > >> *(require <modulename>) *<br>
> > > >> This only gets evaluated once, when the server is started. That<br>
> > doesn't<br>
> > > >> help, since the <filename> is going to be passed in as a parameter<br>
> > while<br>
> > > >> the server is running.<br>
> > > >><br>
> > > >> *(dynamic-require <** modulename **>) *<br>
> > > >> This gets evaluated only when invoked, and thus can take <modulename><br>
> > as<br>
> > > >> a parameter, but then <filename> can't be reloaded (this is<br>
> > essential, as<br>
> > > >> the point of the system is to be able to edit the files and see the<br>
> > changes<br>
> > > >> in the web browser immediately)<br>
> > > >><br>
> > > >> *(enter! <modulename>)*<br>
> > > >> This reloads the file, but it's not clear how to get access to names<br>
> > > >> provided by <modulename>. (The documentation for enter! suggests that<br>
> > this<br>
> > > >> is not how it's meant to be used anyhow.)<br>
> > > >><br>
> > > >> Obviously, I could call a new instance of Racket as a system command,<br>
> > but<br>
> > > >> that wouldn't offer any advantage over the current approach.<br>
> > > >><br>
> > > >><br>
> > > >> I suppose what I'm looking for is an equivalent of the Python<br>
> > > >> reload(<modulename>) command.<br>
> > > >><br>
> > > >><br>
> > > >> Matthew Butterick<br>
> > > >><br>
> > > ><br>
> > > ><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>
</div></div></blockquote></div><br></div></div>