[plt-scheme] In your words what is continuation passing style and what is its important?
On Sun, 24 Jun 2007, Grant Rettke wrote:
> In your words what is continuation passing style and what is its
> important?
PLAI talked about CPS in good detail in Section 7, relating it to how
people write multi-stage web programs:
http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/
Also, the paper "Toward Leakage Containment" helped get my head around
continuation passing style a bit more and why it's useful:
http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR346
In my own programming, CPS tends to hide but I do conceptually use it.
Concretely and most recently, I'm working on a next revision of DivaScheme
--- an extension to DrScheme --- and one part involves taking one's
location and computing what happens to that location after going across
some text. (i.e. I'm on line 5, column 3, and I want to know that after I
go past " \n" that I'm on line 6, column 0).
Conceptually, you might think of it as:
update-location: location text -> location
But in fact, this is not what I directly do. Rather, I split things up in
a slightly strange way:
get-move-after: text -> move
apply-move: move location -> location
and I get the effect of update-location by doing something like:
(apply-move (get-move-after a-text) a-location)
Conceptually, my "move" here acts as a continuation that I can later
choose to apply to a location to shift it around. The reason I'm doing
this in such a funny way is because this gives me the freedom to memoize
the effect of moving across a-text starting from a-loc. It's just a
matter of using Dave Herman's memoize PLaneT package, and a very cool
no-effort optimization.
I can do this only because I'm explicitly holding onto the "what to do
next" thing as a real object. And I can reuse this continuation on
different locations without any problems. I'll be releasing the code
shortly on PLaneT so you can take a look.