News for hackers. Stuff that matters.
Re:Functional programming in Python by andreasvc on Friday May 11, 2012 @06:26PM (#3961764)
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?
Re:Functional programming in Python by swannodette on Friday May 11, 2012 @06:42PM (#3961830)
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.
Re:Functional programming in Python by recursive on Friday May 11, 2012 @06:58PM (#3961897)
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 by pjscott on Saturday May 12, 2012 @12:35AM (#3962768)
A tuple, behind the scenes, is just a type tag, a refcount, a length, and an array of PyObject pointers. A list, instead of having a fixed array of PyObject pointers, has a pointer to a dynamically resizable array of them. Tuples and lists are both iterable, they both have O(1) indexing and fairly efficient internal representations, but the key difference is mutability. A tuple is supposed to be a composite data type; a list is a dynamic array that you store things in.

Aside from mutability, though, tuples can do pretty much anything lists can, and usually a bit more efficiently.

Re:Functional programming in Python by swannodette on Friday May 11, 2012 @07:05PM (#3961918)
Performance? Unless I'm mistaken you can't update tuples efficiently.
Re:Functional programming in Python by nknight on Friday May 11, 2012 @07:23PM (#3961955)
How do you intend to "update" an immutable list? Isn't it... immutable?
Re:Functional programming in Python by lihaoyi on Friday May 11, 2012 @10:39PM (#3962496)
Immutable lists can be preppended/popped in O(1)time, without affecting previous versions.

Immutable dicts can have stuff added and removed in O(log n) time, without affecting previous versions.

Scala's immutable vectors can have appending/prepending/concatenation/splitting/insertion/deletion in O(log n) time, without affecting previous versions. it's log base 32, so for any arrays using integer indexes, it'll never go above ~7, so it's basically constant.

Basically, you get (almost) the performance of mutable data structures, except you don't mess up the old versions of the thing every time you change something. It's really pretty incredible, the performance characteristics people manage to get with structural sharing: http://www.scala-lang.org/docu/files/collections-api/collect...

Re:Functional programming in Python by sureshv on Saturday May 12, 2012 @12:00PM (#3964230)
There's still a lookup hit of log-b32n versus contiguous memory immutable vector with O(1). Locality can also an issue with tree-like structures but muted with the large branch factor. Of course the flip side scala gives you the kitchen sink for persistance.
Re:Functional programming in Python by soc88 on Saturday May 12, 2012 @11:58AM (#3964219)
The Scala stuff is impressive. Updated docs at the new site: http://docs.scala-lang.org/overviews/collections/performance...

The new ConcurrentTrie is also a great addition to 2.10.

Re:Functional programming in Python by snprbob86 on Friday May 11, 2012 @08:00PM (#3962069)
As a pure function where the returned value utilizes structural sharing with the input values.
Re:Functional programming in Python by swannodette on Friday May 11, 2012 @08:26PM (#3962160)