An In-Depth Look at Clojure Collections
infoq.com
infoq.com
(Google for a discount code)
Ok, but then is there a reason to have immutability with collections that aren't shared by multiple threads? I love that Clojure is trying to address these big problems, but I'm not convinced they're on the right track.
The difference is that in Clojure they're really, really fast since they share structure, giving you ridiculously close to mutable performance in some cases. And you don't have to worry about expensive copy operations or things blowing up because you accidentally casted away from const, etc.
It's one of those features that once you're used to, you get a sad face when you look at everything else.
Thats a neat way of putting it, that it sort of makes the collection 'const'. I'll have to ponder how many bugs/problems are due to that type of error, and if its worth the small performance hit of not using arrays.
I'm not sure I'm quite convinced the trade offs are worth it, but considering it further now.
But, I don't think any old linked list can be safely read and modified from a multithreaded environment without threading issues...
I think so. What about this scenario:
Point foo = new Point(10, 0);
frob(foo);
zap(foo);
What's the value of foo.x? foo.y?
I have no idea.In Clojure:
(def foo {:x 10, :y 0})
(frob foo)
(zap foo)
What's the value of foo? {:x 10, :y 0}That certainty is valuable.