[plt-scheme] web-server and templates

From: Mike Burns (netgeek at speakeasy.net)
Date: Sat Aug 14 16:38:34 EDT 2004

--- Jordan Johnson mumbled on 2004-08-14 12.59.55 -0700 ---
> While I'm at it (and this is definitely more of a CGI question, but 
> related--pardon me): if I want to determine which URL or form data to use 
> based on a single click--and *don't* want to use a form submit button--is 
> this the only way:
> 	`(a ((href ,(string-append url "?arg=suchandsuch"))) "click here")
> ?

What you seem to want is `send/suspend/dispatch'. It will be part of a 
future release of the PLT Web server. Until then, I've been using this:

;; send/suspend/dispatch : Response -> void
(define (send/suspend/dispatch p-exp)
 (let/cc k0
     p-exp (lambda (proc)
             (let/cc k1 (k0 (proc (send/suspend k1)))))))))

(define (replace-procedures p-exp p->a)
    ((list? p-exp) (map (lambda (p-e) (replace-procedures p-e p->a))
    ((procedure? p-exp) (p->a p-exp))
    (else p-exp)))

And a very simple example use is:

 (define (callback req)
   `(html (head (title "Page Two"))
          (body (h1 "Page Two"))))

   `(html (head (title "Page One"))
          (body (h1 "Page One")
                (p (a ((href ,callback)) "Page Two")))))

Mike Burns netgeek at speakeasy.net http://netgeek.ws

Posted on the users mailing list.