continuations

In Order of Importance?

April 14, 2005 19:13:28.369

The inimitable David Heinemeier Hansson points out that in a recent set of slides by Sam Ruby, Rails is the fourth item from the top on a list of things Worth Watching. What's item number three? Continuations.

Sam also brings us Continuations for Curmudgeons, an explanation of call/cc from the point of view of a C programmer. I've also often found that explaining continuations in terms of the possible machine (or virtual machine) implementation often gets the point across much easier than trying to explain the semantics. How do you capture a continuation? You save a copy of the current execution stack. How do you invoke it? You blow away the current stack and replace it with a fresh copy of the one you saved. How many times can you do this? As many as you like.

Just don't explain it that way around Scheme folk...

Comments

Re: order of importance

[Sam Ruby] April 14, 2005 22:04:52.846

No.

If I was to do the chart over, I would do it this way:

  • Client: GreaseMonkey / Asynchronous JavaScript
  • Wire: REST
  • Server: Ruby on Rails / Continuation

Scheme folk

[Dave Herman] April 16, 2005 10:35:53.784

Hey, as a Scheme folk myself I have to say I think that's a perfectly great way to explain it. (In fact, I posted Sam's story on Lambda the Ultimate.) There are many angles to take when talking about continuations, and a good teacher doesn't try to teach starting from the most precise, formal definition of a concept but starts with concepts familiar to the audience.

Also, a common confusion with continuations is that they're like transactions and roll back the entire program state to where it was before; talking about the stack vs. the heap helps distinguish which parts get rolled back and which don't.