After we worked through the examples of converting programs to script position, I showed an example of web programs designed to run on the MzScheme web server. Here is the code I showed.
First, here's the original count delay routine:
(define (count-delay)
(let ([new-delay (prompt-read-num "Delay: ")])
(cond [(= 0 new-delay) 0]
[else (+ new-delay (count-delay))])))
Here's the script-position version:
(define (prompt-read-num/web prompt action)
(begin
(printf prompt)
(action (read))))
(define (count-delay/web action)
(prompt-read/web
"Delay: "
(lambda (box)
(let ([new-delay box])
(cond [(= 0 new-delay) (action 0)]
[else
(count-delay/web
(lambda (box)
(action (+ new-delay box))))])))))
Here's the same program written to run with the Scheme server. Note that the count-delay program runs on the server as it was originally written, without the need to convert to script position. How is that possible? The Scheme server has a special construct called send/suspend. That construct builds the (lambda (box) ...) expression automatically and passes it along to action as a URL.
This is an example of the kind of powerful feature a programming language can provide to support a particular programming domain. With send/suspend, you get all the power of a full language like Scheme combined with the specialized web support of custom web languages.
|
This page maintained by Kathi Fisler Department of Computer Science Worcester Polytechnic Institute |