<div>Steve - </div><div><br></div>Others will correct me if I have this wrong, but IIRC #:servlet-namespace is for sharing the namespace with other servlet modules, not for defining the namespace for eval. <div><br></div><div>
It looks like by default the current-namespace is empty (maybe web-server set it to racket/base but in repl it's empty), so parameterize or explicitly pass in a well defined namespace appears to be the way to go. The simplest way I've found is using the module's namespace, since parameters and structs will be instantiated again in another module so if you use them your code will "mysteriously" fail if you don't use the "same" namespace (there are other ways of achieving the same effect but more complicated). </div>
<div><br></div><div>To do so use define-namespace-anchor in the module, and then convert it into a namespace via namespace-anchor->namespace. You can then parameterize or explicitly pass it into eval. </div><div><br></div>
<div>Also I would suggest you replace "FAIL" with (format "FAIL: ~a" (exn-message f)) instead, so you can see the actual error that would aid debugging. Your eval contains an error as it needs a quote for the list (1 2 3). Not sure if your problem was due to this missing quote or not, as it could be just a typo for the email, but having the actual error message will aid the determination. </div>
<div><br></div><div>HTH. Cheers,<br><div>yc </div><div><br><div class="gmail_quote">On Thu, Sep 30, 2010 at 1:40 AM, Steve Knight <span dir="ltr"><<a href="mailto:stknig@gmail.com">stknig@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
I'm using Racket 5.0.1 (from emacs) and I'm having trouble<br>
understanding some behaviour I'm seeing in the web server.<br>
<br>
If I start a servlet and dispatch some URL to this function:<br>
<br>
(define (ev request)<br>
`(div (h1 "Last = " ,(format "~A" (last '(1 2 3))))<br>
(h1 "Last = " ,(format "~A"<br>
(with-handlers ((exn:fail? (lambda<br>
(f) "FAIL")))<br>
(eval '(#%top-interaction .<br>
(last (1 2 3)))))))))<br>
<br>
I get "Last = 3" and "Last = FAIL" as the result, and I think I<br>
understand why. Looking at the code of the web-server I think it is<br>
because the web-server places each servlet in its own namespace and<br>
that namespace does not include racket/list. Therefore I think what<br>
is happening is that the first 'last' is compiled (from #lang racket)<br>
and so is fine and the second 'last' is not and so relies on the<br>
current-namespace. Now because of the namespace fandangling done to<br>
preserve servlet separation, current-namespace is made from<br>
'make-base-namespace' and so does not include racket/list. So far so<br>
good.<br>
<br>
I can make this work by changing the call to eval to pass a well-known<br>
namespace to 'eval' but that is a bit awkward (and feels a bit wrong).<br>
It seems like the right thing to do is to use the<br>
#:servlet-namespace option in serve/servlet (i.e.<br>
"#:servlet-namespace '(racket/list)") but when I try it it has no<br>
obvious effect although looking at the web-server code it seems like<br>
it should.<br>
<br>
Can someone tell me what I'm doing wrong?!<br>
<br>
Steve</blockquote></div>
</div></div>