Hacker News new | past | comments | ask | show | jobs | submit login

I'm not sure what persistent means in this context, but what is meant by "fast" immutable array here is that the immutable array supports operations like insert and delete (returning new immutable objects) in near-constant time.



From Wikipedia [1]:

    a persistent data structure is a data structure that always preserves the previous version of itself when it is modified
So when you do an insert, you get back a new array with the inserted value, and the old array is (as far as external visibility) untouched.

An immutable array is just an array that never changes. A persistent array allows you to do operations on immutable arrays which returns new immutable arrays that is the old immutable array with the operation performed.

[Edit] As sgk284 pointed out elsewhere in the thread, my last paragraph mischaracterises the situation slightly.

An immutable array with any operations defined on it will necessarily be persistent, so it was misleading to say 'is _just_ an array that never changes'.

[1] http://en.wikipedia.org/wiki/Persistent_data_structure


Rich Hickey (re)popularized the usage of "persistent" to mean what you just described immutable as. That is, the previous version of the data structure "persists" after you add an element, and now you have two values.

To the people using that definition of persistent, "immutable" just means constant, i.e. no insertion or deletion at all.


That's not quite right. All immutable data structures are persistent, but not all persistent data structures strictly use immutability.

Immutability is a common way of achieving persistence, but fundamentally a persistent data structure simply preserves previous versions. This can be achieved through some mutability via things like fat nodes[1].

It turns out that when you use immutability, many other nice properties often fall out from that decision. You can absolutely insert and delete into an immutable data structure though. You'll simply get back a new structure.

[1] http://en.wikipedia.org/wiki/Persistent_data_structure#Fat_N...


To give some more context, 'persistent data structures' is a standard term in the literature.

The use of efficient persistent maps in Clojure, and the fact Rich Hickey explains that in most of the early Clojure introductory talks, has popularised it outside of academia.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: