Earlier quoted context omitted.
What do you mean with lack of persistent data-structures? There are immutable data-structures such as numbers, strings, tuples, and frozensets (unfortunately no frozen dicts) -- seems plenty to me. Or do you mean the technical meaning of persistent data-structures, as in one that gives access to all previous versions?
A good set of persistent data structures would give you all the generality, utility, and performance of Python data structures like lists and dicts and none of the mutability.
Functional programming in Python
31–40 of 64 posts
Re: Functional programming in Python
#32as has been pointed out, python isn't particularly great at doing hardcore functional programming due to lack of native persistant datastructures. however i've found it great for learning functional programming without having to get used to the syntax of real functional languages. here are some different ways to implement functional sequence operations without native python syntax like `yield`: https://github.com/dus…
Re: Functional programming in Python
#33Earlier quoted context omitted.
A good set of persistent data structures would give you all the generality, utility, and performance of Python data structures like lists and dicts and none of the mutability.
I don't know about dicts, but as far as I can tell, tuples give you all the generality, utility, and performance of lists.
Re: Functional programming in Python
#34Earlier quoted context omitted.
I don't know about dicts, but as far as I can tell, tuples give you all the generality, utility, and performance of lists.
Performance? Unless I'm mistaken you can't update tuples efficiently.
Re: Functional programming in Python
#35Earlier quoted context omitted.
That works but it's kind of a pain that the natural pythonic syntax: ['a'].extend(some-list) doesn't return a list.
that is not the natural pythonic syntax. for concatenating lists, "+" is standard
http://docs.python.org/release/1.4/lib/node10.html#SECTION00...
Re: Functional programming in Python
#36Re: Functional programming in Python
#37Earlier quoted context omitted.
What do you mean? What would you add on top of the built-ins and stdlib data structures?
There are situations where balanced search trees are appropriate. A general purpose priority queue (with delete and decrease-key operations); there's actually code for this in the _documentation_ of the heapq module; this seems really odd to me, why not just include it? It's also a shame that heapq is built on list instead of being a first-class data-structure, it feels bolted-on. Bitwise tries would be nice as well.
Re: Functional programming in Python
#38Earlier quoted context omitted.
Performance? Unless I'm mistaken you can't update tuples efficiently.
How do you intend to "update" an immutable list? Isn't it... immutable?
Re: Functional programming in Python
#39One thing that's been key for me is namedtuple (in the collections module). It's immutable like a tuple, but the values can be accessed by name just as if they were object attributes built with the class keyword. It's great for creating generic functions (think Lisp and CLOS) instead of using Python's prototypical system. And since tuples can contain any objects and functions are objects, you can bind callables like…
namedtuple is awesome, until you realise it works internally by using eval and generating the source code of a class.
Re: Functional programming in Python
#40as has been pointed out, python isn't particularly great at doing hardcore functional programming due to lack of native persistant datastructures. however i've found it great for learning functional programming without having to get used to the syntax of real functional languages. here are some different ways to implement functional sequence operations without native python syntax like `yield`: https://github.com/dus…
I would have thought the broken statement/expression dichotomy would be a bigger annoyance, though I've never used Python in anger myself.