3 ms·
Immutability means that if you're "modifying" the structure you must actually be "making a new copy with a small change". Structural sharing means that usually
by tel 13y ago
Immutability means that if you're "modifying" the structure you must actually be "making a new copy with a small change". Structural sharing means that usually only the small change itself gets new allocation, but it's still more pointer-chasing than a continuous memory map.
Lots of algorithms don't work with this kind of copying semantics, but you have all of Purely Functional Data Structures [1] to help.
[1] http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504 http://www.amazon.com/Purely-Functional-Structures-Chris-Oka...
- kleiba 13y agoFair enough, but I wasn't talking about modification, I asked about iteration.
- cgag 13y agoJust iterating doesn't make any copies. Replace iterating over with modifying. Efficient immmutable data structures are easily one of Clojure best features. Easiest trade off ever (though the actual hit to performance isn't that bad) imo.
- dragandj 13y agoNot only that, but you can also make a persistent structure locally transient for the duration of the (modifying) iteration, so in lots of cases you do not have to pay the persistence penalty.
- tel 13y agoOh, true—I jumped his point