<div dir="ltr"><div>Thanks, I'll try that. However, I still think there might be a bug in racket/enter.rkt. Currently lines 10-11 look like this:<br></div><div><br></div><div><div> [(enter! mod flag ...) (andmap keyword? (syntax->datum #'(flag ...)))</div>
<div> #'(do-enter! 'mod '(flag ...))]</div></div><div class="gmail_extra"><br>But when I remove the quoting from mod in line 11, like so …<br><br><div><div> [(enter! mod flag ...) (andmap keyword? (syntax->datum #'(flag ...)))</div>
<div> #'(do-enter! mod '(flag ...))]</div></div><div><br></div><div class="gmail_extra" style>Then (enter! module-name-variable) works as hoped, and (enter! "module-name-string.rkt") still works too.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra" style>Making it work proves nothing ;) I will file a bug report.</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>Matthew Butterick<br>
</div><div class="gmail_extra" style><br></div><div class="gmail_extra"><br></div><br><div class="gmail_quote">On Sat, Apr 27, 2013 at 7:17 PM, 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">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>
<div><div class="h5"><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 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, 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 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 <<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 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 server<br>
> >> just sends the files to Racket via a system command (os.Popen) and 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 server<br>
> >> in Racket. But having tried a few approaches, I'm not sure how to duplicate<br>
> >> this functionality within a Racket web servlet:<br>
> >><br>
</div></div>> >> *(require <modulename>) *<br>
<div class="im">> >> This only gets evaluated once, when the server is started. That doesn't<br>
> >> help, since the <filename> is going to be passed in as a parameter while<br>
> >> the server is running.<br>
> >><br>
</div>> >> *(dynamic-require <** modulename **>) *<br>
<div class="im">> >> This gets evaluated only when invoked, and thus can take <modulename> as<br>
> >> a parameter, but then <filename> can't be reloaded (this is essential, as<br>
> >> the point of the system is to be able to edit the files and see the changes<br>
> >> in the web browser immediately)<br>
> >><br>
</div>> >> *(enter! <modulename>)*<br>
<div class="im">> >> 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 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, 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>
</div>> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div><br></div></div>