Live data from Hacker News

Hey, C Is a Functional Language Too

spin.atomicobject.com

21–30 of 78 posts

Re: Hey, C Is a Functional Language Too

#22
I think that this is an interesting area. We can support just about any style in an existing programming language, but there are often rough edges.

This reminds me of how I used to mimic OO in C years ago. At a certain point you realize that you have to forgo certain things to help the person coming after you avoid making mistake -- often they do not see the ramifications of your conventions.

I see this in Ruby right now when I write in a functional style. The code is often terse yet easy to read, but the lack of lazy evaluation makes it far more memory consumptive than code written in a straightforward procedural style. If you know you are making the tradeoff, it is fine. For many people, it is too subtle.

Re: Hey, C Is a Functional Language Too

#23
post #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.

I'm not that old but I remember that, back in the days, functional meant just that you are able to use plain functions (without objects) and pass them around. By that definition, C is functional language, as scheme or lisp or javascript and many others.

I don't know why, but some years ago, "functional programmers" started to change and twist the definition of functional language step by step, until all those languages fell off and only Haskel remained as "functional enough".

Re: Hey, C Is a Functional Language Too

#24
post #18
post #11

Earlier quoted context omitted.

Doesn't function pointers enable passing functions around in C?

Yes, but functions aren't truly first-class values; you cannot create new ones on-the-fly (proprietary extensions notwithstanding).

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

#25
post #24
post #18

Earlier quoted context omitted.

Yes, but functions aren't truly first-class values; you cannot create new ones on-the-fly (proprietary extensions notwithstanding).

What does proprietary mean in this context? I'm sure it can be copied/implemented by for example gcc if they were interested.

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

#27
post #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.

I'm not that old but I remember that, back in the days, functional meant just that you are able to use plain functions (without objects) and pass them around. By that definition, C is functional language, as scheme or lisp or javascript and many others. I don't know why, but some years ago, "functional programmers" started to change and twist the definition of functional language step by step, until all those languag…

I don't see much use in a definition of "functional language" that includes nearly every computer language. We already have a term for that.

Re: Hey, C Is a Functional Language Too

#28
Quick question: why does he do this?

    int main(int argc, char * argv[]) {
      (void)argc;
      (void)argv;
I've programmed C while in school, but I don't remember ever seeing this and I'm not sure how to google it.

Re: Hey, C Is a Functional Language Too

#29
post #21

...and pigs can fly, if you throw them fast enough. This is just an encoding of a Turing-complete language into another, I don't see what's been demonstrated here.

I'm not sure this is even Turing complete considering the limitation he mentions:

>The main limitation is that you need to know the size of the return value.

Re: Hey, C Is a Functional Language Too

#30
post #28

Quick question: why does he do this? int main(int argc, char * argv[]) { (void)argc; (void)argv; I've programmed C while in school, but I don't remember ever seeing this and I'm not sure how to google it.

It stops the compiler from complaining about unused variables:

http://stackoverflow.com/questions/8052091/void-cast-of-argc...

Post reply on HN