r/Python • • Sep 29 '16

O'Reilly offers "Functional Programming in Python" by David Mertz as free eBook.

http://www.oreilly.com/programming/free/functional-programming-python.csp?cmp=em-prog-free-na-lgen_safari_20160929
847 Upvotes

69 comments sorted by

View all comments

Show parent comments

18

u/ubernostrum yes, you can have a pony Sep 30 '16

It's worth noting that most "Python is bad for FP" views -- including the one you linked -- really boil down not to "Python is bad at FP", but rather "Python allows this to coexist with other paradigms of programming". Most of the things people then say they'd want to make Python "better" at FP ultimately are "turn Python into a single-paradigm FP language", not "keep Python multi-paradigm, but improve the FP constructs".

14

u/DonaldPShimoda Sep 30 '16

Hmm but some of the fundamentals aren't quite right. Like tail recursion — that's a pretty big deal for FP, and Python is bad at it by design.

Don't get me wrong; I love Python! It's my preferred language, in fact. But because it wasn't built to be functional from the beginning, it will likely never be able to be used as a "good" functional language.

11

u/wting Sep 30 '16

Hmm but some of the fundamentals aren't quite right. Like tail recursion — that's a pretty big deal for FP, and Python is bad at it by design.

Disclaimer: The definition of FP is a ambiguous and thus quite open to interpreation.

I think TCO is a bit of a red herring. Haskell only does it when compiled with -O2, Scala requires function annotations. Clojure defaults to TCO, and most but not all Lisp dialects support TCO in some form. In practice, Haskell generally prefers folds over recursive calls + TCO.

Also you can hack in Python with a decorator.

2

u/kankyo Sep 30 '16

Clojure has a fancy go to/continue, not TCO