3 ms·
It is a good thing. And it's as simple as e.g. (dosync (ref-set ref newval)). In fact, if you find yourself doing it a lot (don't, please!) then define yoursel
by ihodes 16y ago
It is a good thing.
And it's as simple as e.g. (dosync (ref-set ref newval)). In fact, if you find yourself doing it a lot (don't, please!) then define yourself a little function (defn rset [r v] (dosync (ref-set r v))).
Must isn't that bad of a word, and it's a Lisp: what kind of boilerplate do you expect to write? I prefer it going on none.
It's definitely worth checking out, and if you need state, and you'll need it rarely if at all, you're better served using the built-in STM and the wonderful functions that allow you to manage it (like add-watch; what a lifesaver in a state-heavy app like a GUI) to handle the mess.
- herdrick 16y agoI don't understand you. If you don't like to write boilerplate, why do you appreciate Clojure making mutation verbose? There are times when the imperative style is more natural.
- herdrick 16y agoI don't understand you. By this I merely meant, "I don't understand what you are saying". Hope that was clear.