3 ms·
I have read somewhere else (https://softwareengineering.stackexchange.com/questions/118703/where-did-the-notion-of-one-return-only-come-from/118793#118793 https
by cesarb 9y ago
I have read somewhere else (https://softwareengineering.stackexchange.com/questions/118703/where-did-the-notion-of-one-return-only-come-from/118793#118793 https://softwareengineering.stackexchange.com/questions/1187...) that the "single exit" rule was not actually about having only one place where the function returns, but actually about having a single place where the function returns to.
That rule seems to have been so successful, that no modern language I know of allows (the original definition of) multiple entry or multiple return (except for exceptions).
- chaboud 9y agoForth may not qualify as "modern" for some (though it still has a way of staying around in some contexts, like bootloaders), but it does allow code to store to and retrieve from the return stack, which is also used for loops. If you read that and thought "does that mean I can change loop iteration order and returns programmatically?!?" and/or "WTF?!", the answer is, yes, to all of it. WTF indeed. I've never actually seen a non-pathological use for this language feature.
- tpush 9y agoMultiple entry/exit points is the defining characteristic of coroutines(as described by Knuth.) The functional equivalent would be (delimited) continuations and is extremely powerful (but potentially confusing in an untyped context.)