3 ms·
Delimited continuations are a powerful new control flow construct that's available starting in Scala 2.8. In addition to useful applications like automatically
by stephenjudkins 17y ago
Delimited continuations are a powerful new control flow construct that's available starting in Scala 2.8. In addition to useful applications like automatically transforming blocking, synchronous code into asynchronous code, it can also be abused to add in the tragically missing goto statement (in a limited form) to the language.
This clever implementation also uses exceptions for flow control. If you examine the debugging output from the continuations compiler plugin, you can see how this implemented. Basically, code around a 'shift' statement is segmented into two functions--one before the shift and one after. The one after is turned into a callback from the first.