Hacker News new | ask | show | jobs
by IsTom 5 days ago
I'd rather compare CPS to goto than regular imperative computation.
2 comments

A function call that's not artificially restricted to return to its caller is equivalent to a goto. See "Lambda: The Ultimate GOTO" by Guy Steele.

A continuation is a value that's passed to a function to tell it where to send its result when it's complete.

In imperative programming languages which invariably have restricted function calls, the continuation that every function receives is the address following the function call. This was just a mistake which the earliest programming languages committed, which has been perpetuated ever since, except in functional languages.

The continuations in CPS are closures. Goto basically isn't. GCC's computed goto is, but generally when people say 'goto' they mean the traditional C goto, which involves no closures. The goto analogy is not great for this reason.

A better analogy is that continuations are reified function call return addresses, since return addresses come with a frame pointer (explicit or implicit), and therefore are closure-like.