3 ms·
Not all control-flow primitives are necessary. Eg Haskell and Scheme get by without 'while' and 'goto'. Haskell would do just fine without a built-in 'if': yo
by eru 10y ago
Not all control-flow primitives are necessary.
Eg Haskell and Scheme get by without 'while' and 'goto'.
Haskell would do just fine without a built-in 'if': you can define 'if' as a function via pattern matching.
Given that perspective, the article would be a call to use more expressive types than Booleans to match on---and in lots of cases not to match at all, but provide what would be the result of the match as an argument to the function.
- qwertyuiop924 10y agoScheme and Haskell have other primitives that take the place of while and goto. But yes, using more expressive match types or parameters is a good idea. As for providing the result as an argument, that can be a good pattern, but isn't always practical. Note what I said in my original comment about using your own discretion.
- eru 10y agoThey don't have `other primitives': they have function calls. Most languages have function calls these days.
- qwertyuiop924 10y agoYes, I read LTUI and LTUD. But in most languages, function calls and loops don't have the same semantics. I'll call that a different loop primitive.
- eru 10y agoFor C, this seems to be implementation defined. (At least for C as encountered in the wild, I don't know about C the standard.) Most modern C compilers support tail call optimization. I don't know about `most languages'. Eg I know Java on the JVM doesn't do tail call optimization. Lots of languages probably do not require TCO of their implementations, though.