Hacker News new | ask | show | jobs
by DevelopingElk 4 days ago
CPS is a way of embedding imperative computation into an FP language. I think they built a mini compiler for their binary relation language, which is then Jitted by Julia.
1 comments

I'd rather compare CPS to goto than regular imperative computation.
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.