News for hackers. Stuff that matters.
Re:Hey, C Is a Functional Language Too by cschramm on Friday November 02, 2012 @05:53AM (#4731905)
No it's not. What makes a language functional is its ability to eliminate tail recursion.
Re:Hey, C Is a Functional Language Too by charliesome on Friday November 02, 2012 @05:59AM (#4731916)
GCC 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.

Re:Hey, C Is a Functional Language Too by Jach on Friday November 02, 2012 @07:18AM (#4732083)
GCC 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)
Re:Hey, C Is a Functional Language Too by eru on Friday November 02, 2012 @06:45AM (#4731993)
That'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.

Re:Hey, C Is a Functional Language Too by Evbn on Friday November 02, 2012 @11:18AM (#4733022)
How do you write a function to sum a list of a billion elements in Haskell?

What would happen without tail call elimination?

Re:Hey, C Is a Functional Language Too by eru on Friday November 02, 2012 @02:37PM (#4734093)
With 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.

Re:Hey, C Is a Functional Language Too by dbaupp on Friday November 02, 2012 @06:02AM (#4731923)
That's not a very good definition. It means that GHC-flavoured Haskell isn't functional: http://www.haskell.org/haskellwiki/Tail_recursion
Re:Hey, C Is a Functional Language Too by batterseapower on Friday November 02, 2012 @06:18AM (#4731946)
I 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.
Re:Hey, C Is a Functional Language Too by dbaupp on Friday November 02, 2012 @06:57AM (#4732023)
I believe I have. Thank you for correcting me.
Re:Hey, C Is a Functional Language Too by jfb on Friday November 02, 2012 @08:47AM (#4732345)
Tail-call elimination is a feature of the language environment, not of the language itself.
Re:Hey, C Is a Functional Language Too by Turing_Machine on Friday November 02, 2012 @09:26AM (#4732489)
Not necessarily. The Scheme spec requires tail-call elimination, and I think the same may be true of some other functional-ish languages.