Functional programming in Python
docs.python.org
Functional programming in Python
1–10 of 64 posts
Re: Functional programming in Python
#2Re: Functional programming in Python
#3Re: Functional programming in Python
#4Re: Functional programming in Python
#5What is really missing is a set of decent data structures.
Re: Functional programming in Python
#6Re: Functional programming in Python
#7Earlier quoted context omitted.
What do you mean? What would you add on top of the built-ins and stdlib data structures?
I believe he is talking about persistent data structures.
“… a persistent data structure is a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure.”
Re: Functional programming in Python
#8Re: Functional programming in Python
#9That said, the standard library leaves something to be desired for the functional style. It makes sense for object-oriented programming to have non-mutating functions return the result and mutating functions return None (think sorted vs. sort), but this can get rather irritating when you're trying to write in a purely functional paradigm.
Also, am I forgetting my Python, or does it not have a great solution for appending to the front of a list? One thing I love about Lisp is that it's ridiculously easy to write (cons item some-list), or even (cons item1 (cons item2 some-list)). Doing the same thing in Python is irritating, because insert() doesn't return the result list.
...or maybe that's what I deserve for trying to write Lisp-like code in Python, anyway....!
EDIT: As noted in the comments, the '+' operator will suffice here. Though since lists are really arrays and not linked lists, this functional way of thinking will result in horribly inefficient CPython code.
Re: Functional programming in Python
#10What is really missing is a set of decent data structures.