[racket] Implementing delimited continuations using a CPS transform

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Nov 24 09:41:28 EST 2011

On Nov 24, 2011, at 2:31 AM, Patrick Li wrote:

> Hello everyone,
> Does anyone know of a guide on how delimited continuations (reset/shift) can be implemented using a CPS transform? There is a paper for doing this in Scala, but I don't have a CS background and cannot understand the notation. 
> I thought it might be similar to implementing full continuations using a CPS transform (which I know how to do), but I'm not sure if my solution is the cleanest. Normally, in the CPS transform, each function is extended to take an extra continuation argument. My solution is to extend every function with an additional return-to-reset continuation on top of the extra continuation argument. This 2nd continuation is used by "shift" commands to return to the enclosing "reset", and the original 1st continuation is used to return to the caller.
> Does that sound sensible?

Sure, that's how they created it in 1990. 

But you could also break the tail-call discipline of CPS and translate [shift e] as \k. (k [e](\x.x)) 
Or you can use our 'abstract' continuations to manipulate a stack of continuations directly. 

-- Matthias

Posted on the users mailing list.