Call-with-current-continuation demystified
Many interpreted languages (though sadly not Javascript, yet) include a feature called call-with-current-continuation.
As usually described, it’s… (deep breath)… a function A that accepts a function B that will immediately be called by the language runtime, passing it a function C that when eventually (optionally) called will cause the previous call to A to return the argument previously passed to C and so take us back to where we started – but only if C was actually called. All clear?
No. Nobody ever learned what it’s for by reading a description like that. It’s the kind of description you can understand only if you’ve already had the thoughts that are expressed in it.
Well, my ambition in life is to explain it in a way that any reasonably experienced Java or C# programmer can understand, so I’ll put my current best effort here. Let me know if it helps, or hinders.
Read more…
