2 ms·
The reason threading is much easier in Clojure is due to immutability. Any changes made to data happen via revisions on existing data. This also means that any
by yogthos 13y ago
The reason threading is much easier in Clojure is due to immutability. Any changes made to data happen via revisions on existing data. This also means that any changes are inherently scoped to the appropriate code branch by default.
Shared mutable data is handled by the STM in Clojure. The STM, in turn, relies on immutable data structures to work. Since data is immutable you can have optimistic locking. Reading existing state is perfectly safe even when a new state is being generated.
This article http://blog.enfranchisedmind.com/2009/01/the-problem-with-stm-your-languages-still-suck/ http://blog.enfranchisedmind.com/2009/01/the-problem-with-st... does a great job explaining why it's notoriously difficult to make a working STM in an imperative language.