Delimited Continuations

Delimited continuations are best thought of as the difference of continuations. Anywhere where one continuation encloses another (i.e. running from one point you reach the second) leads to a well defined difference. Consider a simple subroutine as such a difference, between the entry point to the subroutine and the exit point. In high level languages the exit point of a subroutine is the end of the block or an explicit return statement wholly equivalent to the final statement in a program. So consider a subroutine as if it were a program itself; the entry continuation runs the subroutine and then stops; the exit continuation simply stops. The difference between them is the body of the subroutine followed by some undefined behaviour. When you call the subroutine you provide the context necessary to fully define the thread of execution. The return continuation is implicit and the resulting code is well structured, modular and readable.

Invoking a delimited continuation behaves just like a subroutine call and not like a jump. The return context is necessary to fully define the thread of execution and is provided implicitly at the point of invocation. It is as easy to use such a delimited continuation in as modular and readable way as any subroutine. Capturing a delimited continuation as a first-class value in a high level language involves some new control structures. In Scheme we can define these control structures directly using macros, and then hide call/cc for common use. In other languages we may add only delimited continuations as first-class values. Using the end of a program as the second part of difference it can be seen that delimited continuations encompass ordinary continuations as a special case, so no expressive power is lost in using delimited continuations only.