Live data from Hacker News

Hey, C Is a Functional Language Too

spin.atomicobject.com

1–10 of 78 posts

Re: Hey, C Is a Functional Language Too

#3
post #2

No it's not. What makes a language functional is its ability to eliminate tail recursion.

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

#6
From that it looks like the caller always has to allocate the right amount of space on the stack to hold the result. What if the result size is known only by the callee?

Denying yourself the use of the heap is also going to make closures rather difficult. You can use this style to pass back a function pointer, but the caller would also need to allocate space for the callee's captured variables. Ick.

Re: Hey, C Is a Functional Language Too

#7
post #5
post #2

No it's not. What makes a language functional is its ability to eliminate tail recursion.

That's not a very good definition. It means that GHC-flavoured Haskell isn't functional: http://www.haskell.org/haskellwiki/Tail_recursion

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

#9
post #2

No it's not. What makes a language functional is its ability to eliminate tail recursion.

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

#10
I would say the aspect that defines a functional programming language is the support of higher order functions. I.e. functions that can take functions as arguments and more importantly can return functions as return value.
Post reply on HN