[racket] Calling eval from the web server

From: Steve Knight (stknig at gmail.com)
Date: Thu Sep 30 04:40:49 EDT 2010


I'm using Racket 5.0.1 (from emacs) and I'm having trouble
understanding some behaviour I'm seeing in the web server.

If I start a servlet and dispatch some URL to this function:

(define (ev request)
   `(div (h1 "Last = " ,(format "~A" (last '(1 2 3))))
             (h1 "Last = " ,(format "~A"
                                    (with-handlers ((exn:fail? (lambda
(f) "FAIL")))
                                      (eval '(#%top-interaction .
(last (1 2 3)))))))))

I get "Last = 3" and "Last = FAIL" as the result, and I think I
understand why.   Looking at the code of the web-server I think it is
because the web-server places each servlet in its own namespace and
that namespace does not include racket/list.   Therefore I think what
is happening is that the first 'last' is compiled (from #lang racket)
and so is fine and the second 'last' is not and so relies on the
current-namespace.   Now because of the namespace fandangling done to
preserve servlet separation, current-namespace is made from
'make-base-namespace' and so does not include racket/list.   So far so

I can make this work by changing the call to eval to pass a well-known
namespace to 'eval' but that is a bit awkward (and feels a bit wrong).
  It seems like the right thing to do is to use the
#:servlet-namespace option in serve/servlet (i.e.
"#:servlet-namespace '(racket/list)") but when I try it it has no
obvious effect although looking at the web-server code it seems like
it should.

Can someone tell me what I'm doing wrong?!


Posted on the users mailing list.