

Continuations: One Control Flow Construct to Rule Them All - PieSquared
http://blog.bytefreeze.com/past/2010/4/29/one_control_flow_construct_to/

======
Vivtek
Sigh. I'm 43 years old and only really grasped _closures_ this January. It's
going to take another ten years for my continuation epiphany.

This is what happens when you start with BASIC.

~~~
silentbicycle
Continuations sound confusing because they give you an explicit handle for
something that most languages don't let you reference directly: who gets the
result of the current computation.

Are you familiar with setjmp/longjmp in C? Continuations are similar, but
allow longjmp-ing to the same point multiple times. As you might expect, this
gives you a lot of flexibility in defining control constructs.

You can implement exceptions easily via continuations - pass along an
alternative continuation to receive errors. Continuations are more _general_
than exceptions, backtracking, co-routining, etc., but this generality can
make them seem overly abstract - it can be hard to see what those constructs
have in common.

Hey, and don't worry - I started with BASIC too. (I was five or six.) You
gotta start somewhere. After you feel comfortable with continuations, try
learning about unification. :)

~~~
eru
> Continuations sound confusing because they give you an explicit handle for
> something that most languages don't let you reference directly: who gets the
> result of the current computation.

Yes, unfortunately continuations don't play nice with lazy evaluation.

~~~
cousin_it
How about this? <http://www.haskell.org/all_about_monads/html/contmonad.html>

~~~
eru
Yes, I know about the continuation monad. But that continuations have to be
encapsulated in monads is telling.

I have found a discussion about this <http://lambda-the-
ultimate.org/classic/message10560.html>

------
blasdel
Conditional Jump: _Another_ Control Flow Construct to Rule Them All

~~~
fab13n
Not another, pretty much the same. If you add to "goto" the required stuff to
play nice with closures, you get a continuation.

~~~
blasdel
Was that Functional Completeness not obvious in my joke?

Except that in this case, they're not quite as equivalent as NAND / NOR are —
continuations assume a lot more "required stuff" (as you put it) than just a
basic memory space, a means to test values, and the ability to set the program
counter.

~~~
eru
That is if you approach the requirements from the implementation point of
view. In theory continuations aren't really that much more complex than Gotos.

