Making Conjure a Continuation Server

2 views
Skip to first unread message

Matt

unread,
Nov 15, 2009, 3:36:47 PM11/15/09
to Conjure
I was talking to a coworker of mine earlier this week about ideas for
Conjure, and he introduced me to the concept of a <a
href="Continuation">continuation</a> server. An example being
Smalltalk's <a href="http://en.wikipedia.org/wiki/Seaside_%28software
%29">Seaside</a>.

After doing some research and thinking about it for a while, I
realized, with the combination of macros and anonymous functions, we
could do basically the same thing in Conjure.

What does a continuation server give us? Say you want a website which
asks the user to login, then shows a splash screen with some news if
the user has not already seen it, and finally show the user's home
page. To do that currently in your controller you would have to do
something like:

(defn login [request-map]
(render-view request-map))

(defn splash-screen [request-map]
(if (show-splash?)
(render-view request-map)
(redirect-to request-map { :action "home" }))

(defn home [request-map]
(render-view request-map))

Then your views would have to link to the appropriate next action.
This isn't exactly bad, but it isn't obvious from the code what's
going on.

With a continuation server, you could do something like:

(defn login [request-map]
(render-continuous :login
(render-continous (if (show-splash) :splash-screen)
(render-continuous :home))))

While not perfectly readable, it's easy to see what you expect the
server to do. First, login, then show the splash screen if necessary,
then show home.

We can do this since render-continuous is a macro which renders the
view associated with the given keyword, then makes an anonymous
function out of the given forms. The anonymous function could be saved
in a map keyed by the user's session id and a specially created
continuation id. When the user returns to the web site, the user's
session id and continuation id are used to look up the anonymous
function, which is passed a new request-map and rendering continues.

There are several other advantages to continuation servers.
Unfortunately, I can't find a good explanation of them beyond the book
<a href="http://www.amazon.com/Beyond-Java-Bruce-Tate/dp/0596100949/
ref=sr_1_1?ie=UTF8&s=books&qid=1258316983&sr=8-1">"Beyond Java"</a> by
Bruce Tate.

Advantages I do remember:

The back button always works since it just looks up the previous
continuation on the server.

You don't have to pass around hidden variables, or save partial data
in your database, since this data can be saved in the continuation and
looked up at any time.

Disadvantages:

The user is bound to a single server. Which ever server contains the
continuation for a given user is the only one the user can go to. This
could be over come by keeping track of which server contains the
continuations for a given user in the database.

Continuations could become a memory hog. I'm not sure what could be
done about this, but to make sure the continuations are cleaned up
often.

Unfortunately, I can't start working on continuations until we at
least have sessions. Continuations may be a good goal for the 0.5
release of Conjure.

Robert Postill

unread,
Nov 15, 2009, 4:33:27 PM11/15/09
to clojure...@googlegroups.com
Awesome! I'll frankly admit that other than hearing of Seaside I have
no exposure to that framework or for that matter to a continuation
server but I'm certainly game. Do you you know of any LISP-based
examples of a continuation server?
Robert
PGP.sig

Matt

unread,
Nov 16, 2009, 6:33:03 PM11/16/09
to Conjure
I was about to write I don't know of any continuation servers in lisp,
but I did a google search and found 2:

http://common-lisp.net/project/cl-weblocks/
http://scheme.dk/blog/2007/04/introduction-to-web-development-with.html

I don't know anything about them, but I think I will check them out to
get some ideas.

-Matt
>  PGP.sig
> < 1KViewDownload
Reply all
Reply to author
Forward
0 new messages