What makes Clojure worth it is the pervasive reduction of mutable state across your program without the cost and rigidity of creating types everywhere. Also great sharing of code across Clojure and ClojureScript:
- You want your dates to behave the same on client and server? You got it: https://github.com/juxt/tick
- You want your logging/debugging code to be the same? You got it: https://github.com/ptaoussanis/timbre
- You want good async primitives? No problem: https://github.com/clojure/core.async
- And many more...
I haven't seen another language that is as good as Clojure(Script) at this. Nowadays .cljc (.clj + .cljs) files really rock.
http://www.kylheku.com/cgit/txr/tree/share/txr/stdlib/compil...
Notice how there is a method to take a snapshot of the compiler state, which includes making copies of several hash tables, and a corresponding restore method to put it back. Hey, isn't there some GoF Design Pattern for this? Memento or something.
The thing is, if hash tables and objects were immutable, the whole code would be a shitshow, and perform badly too.
It would just not have that one problem: it would never have to copy a hash table in order to have a copy of the old one.
Immutable HAMT hash tables that I could conj to and then assign back into the original location would be a reasonable middle ground. Then I would still need he snapshot method; but it wouldn't have to do anything beyond returning (copy me).
It occurs to me I could implement a shallow hash table copy function, such that the original and new table share chains. Mutating either table (overwriting an existing key/value pair with a new value) would show up in the other, but deletions and insertions would not.
Then as a developer you are looking into a certain piece of that tree depending on what bit of the "mutated value" you are viewing
I assume this is to help ensure memory usage doesn't balloon but if you need to do mutation there are non-default features for doing that: https://clojure.org/reference/transients with all the pros and cons of mutation
Clojure was designed to, as seamlessly as possible, Trojan a Lisp into the enterprise world where the JVM rules. It succeeded at that narrow task.
That said, the idea of conj bring an extended cons sounds really nice. Are there examples where the "you can change the fundamental data structure and the algo still works" pans out?
I fear this will be a lot like our industry's love of tries. Mostly impractical and more likely to cause bugs. :(