[plt-scheme] web-server and templates
--- Jordan Johnson mumbled on 2004-08-14 15.16.32 -0700 ---
>
> On Saturday, August 14, 2004, at 01:38 PM, Mike Burns wrote:
> >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:
>
> ..an interesting and ingenious approach, indeed.
>
> I don't see how it would work for the purpose of what I was doing
> earlier, though, which required dispatching on two arguments, e.g.,
> <a href="myscript.ss;...?row=2&col=5">2x5</a>
>
> ..or am I missing something? (I'd love to be shown wrong on this. :>)
Using send/suspend/callback, this problem can be entirely avoided. Here's an
example that might help.
(module example-servlet mzscheme
(require (lib "servlet.ss" "web-server")
(lib "etc.ss"))
(provide timeout interface-version start)
(define timeout 15)
(define interface-version 'v1)
(define (send/suspend/callback p-exp)
(let/cc k0
(send/back
(replace-procedures
p-exp (lambda (proc)
(let/cc k1 (k0 (proc (send/suspend k1)))))))))
(define (replace-procedures p-exp p->a)
(cond
((list? p-exp) (map (lambda (p-e) (replace-procedures p-e p->a))
p-exp))
((procedure? p-exp) (p->a p-exp))
(else p-exp)))
(define (blow-up-coordinate! row col)
;;; TODO: the grunt work
void)
(define (transition-explosion row col)
(lambda (req)
(blow-up-coordinate! row col)
`(html (head (title "BLAM!"))
(body (h1 "Ka-BOOOM!")
(p (string-append
"The co-ordinate "
,(number->string row)
","
,(number->string col)
" has exploded."))))))
(define (start req)
(send/suspend/callback
`(html (head (title "Pick a co-ordinate"))
(body (h1 "Pick a co-ordinate")
(ul
,@(map
(lambda (x y)
`(li (a ((href ,(transition-explosion x y)))
,(string-append (number->string x) ","
(number->string y)))))
(build-list 5 identity)
(build-list 5 identity)))))))
)
--
Mike Burns netgeek at speakeasy.net http://netgeek.ws