News for hackers. Stuff that matters.
Re:Hey, C Is a Functional Language Too by zokier on Friday November 02, 2012 @06:57AM (#4732021)
Doesn't function pointers enable passing functions around in C?
Re:Hey, C Is a Functional Language Too by ginko on Friday November 02, 2012 @07:06AM (#4732051)
Yes, but you can't combine function pointers to create and return new functions.
Re:Hey, C Is a Functional Language Too by flatline on Friday November 02, 2012 @10:28AM (#4732728)
Sure you can - just not anonymously. Kind of like how you can have "higher order functions" and "closures" in Java with anonymous classes - roughly equivalent, but awkward and not quite what the language was designed for. C is probably better in this regard than Java, but the lack of managed memory is a major drawback.
Re:Hey, C Is a Functional Language Too by JoeAltmaier on Friday November 02, 2012 @10:31AM (#4732739)
Right. SO you can program 'functionally' in those languages, but they are not 'functional programming languages' because they don't support it natively.
Re:Hey, C Is a Functional Language Too by sixbrx on Friday November 02, 2012 @10:45AM (#4732836)
"just not anonymously"

Just not depending on anything in the environment either except globals, which is a huge limitation. So writing a function inc by = \x -> x + by becomes unnecessarily difficult for example.

Re:Hey, C Is a Functional Language Too by aaronblohowiak on Friday November 02, 2012 @03:41PM (#4734386)
then you just have a void* / fn ptr couple that you pass around..
Re:Hey, C Is a Functional Language Too by jrajav on Friday November 02, 2012 @07:12AM (#4732069)
Yes, but functions aren't truly first-class values; you cannot create new ones on-the-fly (proprietary extensions notwithstanding).
Re:Hey, C Is a Functional Language Too by kzrdude on Friday November 02, 2012 @07:43AM (#4732152)
What does proprietary mean in this context? I'm sure it can be copied/implemented by for example gcc if they were interested.
Re:Hey, C Is a Functional Language Too by jrajav on Friday November 02, 2012 @08:12AM (#4732237)
I meant to refer to extensions implemented independently by one compiler or another. Clang and gcc both provide lambdas, but not in the same way, and there's no standard for it. (I could be wrong on both points; this is purely from memory, and could have changed.)
Re:Hey, C Is a Functional Language Too by kzrdude on Saturday November 03, 2012 @10:16AM (#4736638)
Thanks for your explanation. I had to look and I libblocksruntime which seems to be an open source lib for clang with blocks.
Re:Hey, C Is a Functional Language Too by jvranish on Friday November 02, 2012 @09:17AM (#4732458)
Actually, if you look closely you'll notice that not other language lets you do this either (except through an 'eval' or similar). What I think you actually mean is that this still doesn't let you use closures. But in fact it does! :D You'll have to do a lot of void * casting to make it work though.
Re:Hey, C Is a Functional Language Too by charliesome on Friday November 02, 2012 @10:09AM (#4732656)
C does not provide closures. You can pass around a struct with a function pointer and a data or state pointer though. That will let you achieve the same thing, but it won't be as pretty.