"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog


Tuesday, July 13, 2004

Understanding Continuations

Ian Bicking has an operational, concrete description of how continuations work.

Here's another way of explaining that sometimes works...

  • Imagine running some code in a (good, hypothetical) debugger.
  • Step through the code at the finest level of detail.
  • The "step" command is what the code will "do next, atomically, then stop".
  • The "continue" command (continue without stopping again) is what the code will "do next and thereafter".
  • The "continue" command is the debugger's way to access a continuation.
  • The Scheme function call-with-current-continuation is like the "continue" command of this hypothetical debugger.
  • The difference is rather than having the debugger get access to the continuation, your code itself gets access to the continuation, "disguised" as a procedure rather than as a debugger command.
  • Like any Scheme procedure, this "continuation procedure" can be called over and over again.
  • Like any impure language, though, Scheme side effects like assignment and I/O are not purely functional and so subsequent invocations of the "continuation procedure" take place in the state of the system resulting from earlier side effects.

1 comment:

Chui Tey said...

How about the web browser?

Hitting the back button a few times and navigating to another page is like calling with continuation.

In fact this is why continuations are so interesting because people use the "back" button in web applications as a way to perform undo, and server side applications have a hard time managing the users expectations.

Google for "Seaside" for more.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.