Modal Web Server
Chris Double implemented a simple continuation-based Web framework in Scheme. Here’s an example:
‘show-message’ is a function that displays an HTML page with a message and an ‘Ok’ anchor. The ‘Ok’ anchor goes to an URL as described above:
(define (show-message msg) (show (lambda (url) (sxml->html-string `(html (head (title ,msg)) (body (p ,msg) (p (a (@ (href ,url)) "Ok")))))))We can use this by registering with the server a function that calls it a couple of times:
(register-function (lambda () (show-message "Hello") (show-message "World")))Accessing the registered function displays the first ‘Hello’ page. Clicking ‘Ok’ will then resume the function and display the second ‘World’ page. Clicking ‘Ok’ on that page exits the function.