Sunday, April 4, 2004

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)
   (lambda (url)
        (head (title ,msg))
         (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:

 (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.

Comments RSS · Twitter

Leave a Comment