5 ms·
Persistent data structures are part of it, for sure. But on a higher level. On a lower level, if you look at how and assoc-in works in Clojure, the scales will
by nickbauman 11y ago
Persistent data structures are part of it, for sure. But on a higher level. On a lower level, if you look at how and assoc-in works in Clojure, the scales will fall from your eyes (they certainly fell from mine). Consider:
(def g {:x "a" :y {:k 71}})
user=> (assoc-in g [:y :k] 72)
{:y {:k 72}, :x "a"}
With this you can walk and mod deeply nested datastructures with ease (and others can reason about it well).
- aaron-lebo 11y agoI may be misunderstanding your point, but that's just a well-done function which could be written in virtually any language, the advantage isn't inherent to Clojure.
- natrius 11y agoThe difference is that in Clojure, `assoc-in` is effectively a deep copy as well since the data structures are immutable. Most of the complexity involved with nested maps is about the effects of modifying them. In practice, this doesn't exist in Clojure.
- nickbauman 11y ago> which could be written in virtually any language What natrius says is completely right on this point (which explains why those functions don't exist commonly outside of lisp) but it should by now make you wonder: if that's true, why haven't they?
- aaron-lebo 11y agoOH, I see your point. Thanks for the enlightenment.
- xiaoma 11y agoIt's not true. ImmutableJS is becoming very common, especially for React users: https://github.com/facebook/immutable-js/ https://github.com/facebook/immutable-js/
- dustingetz 11y agoPeople like to talk about immutable.js. It's not common.
- xiaoma 11y ago8k stars and counting. We used it at the last place I worked (a YC startup) and several of my friends report the same.