
Functional C (1997) - X4
http://eprints.eemcs.utwente.nl/1077/
======
colmmacc
There's a common cliché, that C programs, as embodied in Unix, are probably
the most widely used form of functional programming - or at least CSP. This
example is idiomatic;

    
    
         grep -c foo * | uniq | sort -rn
    

It's more than possible to structure C programs this way internally too,
elegant even. Use forks and pipes if you want to keep it simple, build co-
routines if you're up for it. It's probably the most practical and beneficial
way you can re-apply the lessons of FP to C.

But the book doesn't mention either technique - just weird and ugly tricks to
emulate tail-recursion, cons et al, probably the least effective parts of FP
to try to use in C.

~~~
yp_master
"But the book doesn't mention either technique..."

As other commenters are pointing out, the book's aim is to teach imperative
programming with C to students of SML. It is not aimed at teaching functional
programming in C.

The technique you describe -- using what UNIX offers, e.g., pipe and fork --
is used a lot by djb.

This book seems like a gentle intro to C.

And there's nothing wrong with keeping things simple in the beginning.

With respect to books and tutorials on C, I have seen much worse.

Master the basics of C, then go read djb's code for lessons on how to
structure programs and smartly utilise what UNIX has to offer. Keep K&R and
Stevens nearby for reference.

A classic example is passing file descriptors instead of using a pipe function
that opens a shell. There is no book on C that teaches that, but it is elegant
programming indeed.

Even when one strives to keep things simple, C (and UNIX) have many gotchas.

There's a lot to learn.

This book doesn't overwhelm the reader.

Personally, I like the approach.

Lots of short consistent examples.

Lucid writing style, too.

~~~
e12e
That section on linked lists (cons in c and sml) was really nice. I don't
think I've ever seen such clear, plain c for working with singly linked lists
(which even checks the return code for malloc!).

I actually had to look up what K&R had on it, and there's a section on tree-
structures -- but it ends up being cluttered (although that's justifiable in
K&R -- the focus isn't just on simple example code).

Disclaimer: I don't actually know C :-)

[edit: link:
[http://eprints.eemcs.utwente.nl/1077/08/list.html](http://eprints.eemcs.utwente.nl/1077/08/list.html)
]

------
Nursie
Heh. This was my university intro-to-C textbook, and the course was taught by
Pieter Hartel. Great lecturer.

It's not about functional-as-a-religion coding in C, and it really is a
beginners book. Good though.

Pieter always used to say that he got around 50 pence per copy sold (from a
roughly £15 pricetag)and if we found a typo we could have our 50p back :)

------
vitd
I'm confused by the title of this article. The copyright in the PDF is 1999,
not 1997, and it says it's about imperative programming in C, not functional
programming. It says it's for people who learned functional programming in
SML, but now need or want to learn imperative programming.

~~~
ExpiredLink
> " _This book is the course material to teach a second paradigm: imperative
> programming, using C as the programming language._ "

Yep, 'functional' is an overloaded term.

------
gangster_dave
really?

~~~
middleclick
Why not?

~~~
pjmlp
[http://blog.llvm.org/2011/05/what-every-c-programmer-
should-...](http://blog.llvm.org/2011/05/what-every-c-programmer-should-
know.html)

[http://blog.llvm.org/2011/05/what-every-c-programmer-
should-...](http://blog.llvm.org/2011/05/what-every-c-programmer-should-
know_14.html)

[http://blog.llvm.org/2011/05/what-every-c-programmer-
should-...](http://blog.llvm.org/2011/05/what-every-c-programmer-should-
know_21.html)

