[racket] Calling eval from the web server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu Sep 30 06:13:26 EDT 2010

This error probably has nothing to do with the Web server. If you run

#lang racket
(eval '(#%top-interaction . (last (1 2 3))))

Then you get the error:

. compile: unbound identifier (and no #%app syntax transformer is
bound) in: #%top-interaction

If you run the same expression from the REPL you get the error:

. . procedure application: expected procedure, given: 1; arguments were: 2 3

'eval' rarely makes sense with one argument.

Jay

On Thu, Sep 30, 2010 at 2:40 AM, Steve Knight <stknig at gmail.com> wrote:
> Hello,
>
> 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
> good.
>
> 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?!
>
> Steve
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.