23 February 2006

To be continued

An MIT mailing list on lightweight languages poses the warm-up question: What is the value of this expression:

  (call/cc call/cc)

Ready for the main event? Figure out this one:

  ((call/cc call/cc) (call/cc call/cc))

The answer is helpfully missing.

I went through several contradictory answers before figuring out a good way to reason about continuations. I'll put a hint in the comments.

1 comment:

jto said...

I was able to get a better grip on the second problem by mentally compiling the expression to stack-machine code. In this case the stack-machine code would look like this:

LOAD call/cc
LOAD call/cc
APPLY 2
LOAD call/cc
LOAD call/cc
APPLY 2
APPLY 2

Then a continuation is simply an instruction pointer, plus the contents of the stack.

As for the answer, your guess is as good as mine.