3 ms·
Continuations are one functional concept that made 100% more sense in C than it did in Scheme. (Then again, being on a team that wrote a cooperative task based
by com2kid 11y ago
Continuations are one functional concept that made 100% more sense in C than it did in Scheme.
(Then again, being on a team that wrote a cooperative task based callback centric run-time from the ground up really made it all sort of click together. In a very blatant "we should have used continuations sort of way!)
You have a dispatch loop that is in charge of "tasks". A task that wants to be continued later on uses a macro to copy the entire stack from the current point all the way down to the first function call that the dispatcher made for the task.
Copy off that stack and the current instruction pointer to a structure, tada, that is a continuation. Resuming is pretty easy in raw C land.
Compare that to a lovely CS description:
> In computer science and computer programming, a continuation is an abstract representation of the control state of a computer program.
I know that the world isn't all C, but "copy of the stack" is so much easier to grok at first.
Anyways, if at any point in my life I ever get to be part of another team that writes a from the ground up run-time for an embedded system (doubtful), then I'm copy off one of those C macros that does continuations. Our code base would be a fraction of the size!