Live data from Hacker News

Hey, C Is a Functional Language Too

spin.atomicobject.com

31–40 of 78 posts

Re: Hey, C Is a Functional Language Too

#32
At some point the stack is going to grow which will cause allocation at the OS level. And if we're discussing small embedded systems with fixed stacks, this code is entirely unsafe (non deterministic stack usage may cause stack overruns).

In embedded systems (non-MMU ones) you generally want to avoid repeated dynamic runtime allocation to prevent memory fragmentation.

It's a cute example, but I can't see any scenario where its better or safer than heap use.

Re: Hey, C Is a Functional Language Too

#33
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.

It's still Turing complete (though that's not saying much really). You can always grow the stack more :P

Re: Hey, C Is a Functional Language Too

#34

At some point the stack is going to grow which will cause allocation at the OS level. And if we're discussing small embedded systems with fixed stacks, this code is entirely unsafe (non deterministic stack usage may cause stack overruns). In embedded systems (non-MMU ones) you generally want to avoid repeated dynamic runtime allocation to prevent memory fragmentation. It's a cute example, but I can't see any scenario…

> It's a cute example, but I can't see any scenario where its better or safer than heap use.

The author does explicitly point this out: "While I find this style strangely addictive, I don’t think I would advocate its general use."

Re: Hey, C Is a Functional Language Too

#35

Earlier quoted context omitted.

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.

well it's primary use seems to be providing a moving goal post for the functional side during the occasional OO vs Functional skirmishes.

Re: Hey, C Is a Functional Language Too

#36
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.

All programming languages and all programming styles can be similarly dismissed as encoding one Turing-complete form into another. Why pay attention to any of them?

This article is clearly someone having fun with their language. It isn't a serious claim about C being functional, something which the author states explicitly if you read to the end.

Re: Hey, C Is a Functional Language Too

#37
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).

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

#39
post #31
post #2

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

Tail-call elimination is a feature of the language environment, not of the language itself.

Not necessarily. The Scheme spec requires tail-call elimination, and I think the same may be true of some other functional-ish languages.

Re: Hey, C Is a Functional Language Too

#40
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.

I use clang with a -Wall and -Wextra, which will complain about all sorts of stuff I generally want to know about, including unused variables (I think gcc does the same?). For the rare cases where I actually want to leave a variable unused I do the above to make the warning go away.
Post reply on HN