3 ms·
I think `bar` being able to return from `foo` has little difference to throwing exceptions in various OOP languages. But the C-style paradigm makes it more conf
by plagiarist 3y ago
I think `bar` being able to return from `foo` has little difference to throwing exceptions in various OOP languages. But the C-style paradigm makes it more confusing for different scenarios, like as you describe with calling the deeper "return" from main.
- HexDecOctBin 3y agoI'm not an expert, but I think the difference is that in exceptions, stack in unwound; while in continuations, all stack frame hang around in a sea of stack frames waiting to be garbage collected when no one holds a reference to them anymore. This would imply that you can jump into the same stack frame multiple times, or do other weird things.
- harryposner 3y ago> This would imply that you can jump into the same stack frame multiple times, or do other weird things. Yep— this is how you can implement the `amb` operator with call/cc: https://ds26gte.github.io/tyscheme/index-Z-H-16.html https://ds26gte.github.io/tyscheme/index-Z-H-16.html
- plagiarist 3y agoSure, but then the context of the C family of languages hinders any comprehension of these different styles of use.
- harryposner 3y agoSo the particular example here isn’t too different from exceptions. You’re unwinding the stack up to a predefined point— here, the callsite of foo, where with exceptions it would be up to the surrounding try/catch. Scala actually implements non-local returns (the only practical use I’ve had for call/cc) using exceptions: https://tpolecat.github.io/2014/05/09/return.html https://tpolecat.github.io/2014/05/09/return.html