Look how beautifully this is expressed in PLT Scheme:
The send/suspend procedure reifies the current continuation as a web continuation URL. The redirect-to procedure generates a response that redirects the user's browser to the given URL. By combining the two, we simply redirect the user's browser right back to exactly the point in the computation where we are, the only difference being that we've now returned from a "GET" interaction instead of a "POST". Usage looks like:(define (redirect/get)
(send/suspend
(lambda (k-url)
(redirect-to k-url))))
(Added to the Scheme Cookbook.)(define (start initial-request)
(let ([request (send/suspend
(lambda (k-url)
... form ...))])
(redirect/get)
(let ([user (extract-binding/single
'user
(request-bindings request))])
`(html (head (title "Hi"))
(body (p "Hi, " ,user "! Hit refresh!"))))))
2 comments:
Of course, the inner lambda is not necessary:
(define (redirect/get) (send/suspend redirect-to))
Yes, but people might (wait for it..) miss the point!
(Thank you, thank you, don't forget to tip your waiter...)
Post a Comment