[plt-scheme] PLT Web Server

From: Arend P. van der Veen (apvanderveen at att.net)
Date: Tue Jun 29 20:47:56 EDT 2004

Hi.

I am new to PLT Scheme and have been trying to get some experience with 
the PLT Web Server.  I have successfully installed DrScheme version 207 
for Unix (X11) from source on FreeBSD 4.9.    I have been able to access 
URLs from both localhost and from other hosts in my subnet. 

I am particularly interested in the behavior of the "send/*" functions 
supported by* servlet.ss*.   I initially started experimenting with the 
add example (add.ss) but found that I was leaking memory.  I think that 
this is because there is not any "send/finish" in add.ss.  There is only 
a "send/suspend."  I then decided to try and test the example 
multiplication servlet in section 10.4 (figure 2) in the web server 
documentation (version 207.1).    I created a new file called

/usr/local/plt/collects/web-server/default-web-root/servlets/examples/multiply.ss

and copied the contents of the example into it.  When I access

http://127.0.0.1/servlets/examples/multiply.ss

I get the following error:

Servlet didn't load. 
/usr/local/plt/collects/web-server/default-web-root/./servlets/examples/multiply.ss:11:2: 
define: not allowed in an expression context in: (define (answer-page n) 
(quasiquote (html (head (link ((rev "made") (href "mburns at example.com") (...

Does anybody know what the cause of this error is?  Again I am new to 
Scheme so please forgive me if this is a simple error. 

Thanks,
Arend van der Veen

Following is the contents of multiply.ss:

(require (lib "unitsig.ss")
     (lib "servlet-sig.ss" "web-server")
     (lib "servlet-helpers.ss" "web-server"))

(unit/sig ()
  (import servlet^)

  (send/finish (answer-page (* (get-number "first") (get-number "second")))

  ;; answer-page : Number -> Xexpr
  (define (answer-page n)
    `(html
       (head
         (link ((rev "made") (href "mburns at example.com") (title 
"Webmaster"))))
       (body (h1 "Answer")
         (p ,(string-append "The answer is " (number->string n))))))

  ;; get-number : String -> Number
  (define (get-number which)
    (string->number
      (extract-binding/single
        'num
        (request-bindings
      (send/suspend
        (get-number-page which))))))

  ;; get-number-page : String -> String -> Xexpr
  (define (get-number-page which)
    (lambda (k-url)
    `(html
       (head
         (link ((rev "made") (href "mburns at example.com") (title 
"Webmaster"))))
       (body (h1 "Enter a number")
         (form ((action ,k-url))
           (p ,(string-append "Please enter the " which "number"))
       (input ((type "text") (name "num") (id "num")))
       (input ((type "submit"))))))))))







Posted on the users mailing list.