Hey, C Is a Functional Language Too!

“So it turns out C is a functional language too!

On the way to Strange Loop this year, John Van Enk and I were trying to find a way to write some C code that avoided dynamic (malloc) allocation. We discovered a technique that allows you to forgo the use of malloc in many common cases. It also enables very pure functional C code.

You doubt? I shall demonstrate! I will show how you can write a linked list reversal function in C using:

  • No mutation!
  • Linked lists, with no malloc!

And this isn’t just a trick that only works in this special case, it is quite generally applicable.
Behold!…”

http://spin.atomicobject.com/2012/11/01/hey-c-is-a-functional-language-too/

Advertisements