[plt-scheme] Continuations

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Fri Nov 24 09:50:53 EST 2006

--- nish <nish2575 at yahoo.com> wrote:

> but anyways, i just recently sepnt a little time just
> developing scheme servlets (and a scheme server on 
> bytmark!!)

What is bytmark?  Our hosting provider is Bytemark.  Are
they related?

> i've always kept an eye out for when any
> of my apps started to feel like they were turning into 
> wizard type apps. 

By wizards, people often mean linear control flow. 
Continuations do not restrict you to linear control flow, a
misapprehension that I've seen in some places. 
send/suspend/dispatch is the constructive proof of this.
> and most features or new servlets i add to an app, still
> tend to be a
> single request that is handled in the top request loop. i
> think of a
> contination as needed when a request from the top request
> loop needs a
> few nested steps before completeting. i haven't come
> across enough
> times where i need that that nested / wizard flow in an
> app yet. 

Partly, I think this is because most web apps are so
limited.  More complicated apps, like the kind of stuff
Google is doing these days, demand more from the
programmer, and here better abstractions pay off.

One point to be aware of: continuations give you procedure
call semantics for requests (call/return).  A simple
example:  Consider a 'soft' login.  The user is allowed to
browse around a web site but when they try to edit anything
they get sent to a login page.  After a successful login,
they should return to the page they were editing.

Implementation 1: old school

Pass a HTTP parameter to the login page that is the URL to
return to.  The URL must also encode any state on the
editing page that must be restored when the user returns
there.  The login page must remember to call itself with
the correct URL if the login fails.

Implementation 2: continuations

(keep-on-trucking (send/suspend (login)))

The insight is that implementation 1 is manually encoding
control flow (a manual CPS transform).  Whenever this
situation arises, reach for the continuations.


Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.

Posted on the users mailing list.