5 ms·
No it's not. What makes a language functional is its ability to eliminate tail recursion.
by cschramm 14y ago
No it's not. What makes a language functional is its ability to eliminate tail recursion.
- charliesome 14y agoGCC can eliminate tail recursion, so does that make C functional? I don't think the author is seriously of the belief that C is a functional language. This is just a fun little example of writing C in a functional style.
- Jach 14y agoGCC can even eliminate non-tail recursion, such as with this piece of black magic: int factorial(int x) { if (x > 1) return x * factorial(x-1); else return 1; } will be optimized by GCC to int factorial(int x) { int result = 1; while (x > 1) result *= x--; return result; } (http://ridiculousfish.com/blog/posts/will-it-optimize.html http://ridiculousfish.com/blog/posts/will-it-optimize.html)
- dbaupp 14y agoThat's not a very good definition. It means that GHC-flavoured Haskell isn't functional: http://www.haskell.org/haskellwiki/Tail_recursion http://www.haskell.org/haskellwiki/Tail_recursion
- batterseapower 14y agoI think you might have misinterpreted the contents of that page. As someone who has worked on GHC, I can assure you that it does perform tail call optimisation.
- dbaupp 14y agoI believe I have. Thank you for correcting me.
- eru 14y agoThat's a very weird definition. Eliminating tail calls is fun, and useful. But not all that essential in, say, a lazy language. Having first-class function values in the first place strikes me as way more important. Purity helps, too.
- Evbn 14y agoHow do you write a function to sum a list of a billion elements in Haskell? What would happen without tail call elimination?
- eru 14y agoWith foldl', of course. If you don't have tail recursion elimination, foldl' would have to be provided as a built-in. Summing up numbers is inherently strict, so you'd want tail call elimination for that. But functional mainstains, like say, map or filter are usually not implemented with tail recursion in Haskell, because that would be too strict and would break on infinite lists.
- jfb 14y agoTail-call elimination is a feature of the language environment, not of the language itself.
- Turing_Machine 14y agoNot necessarily. The Scheme spec requires tail-call elimination, and I think the same may be true of some other functional-ish languages.