I\'m trying out Clojure 1.2, specifically mutable fields which are supported in deftype
according to the clojure.org documentation.
But I can\'t get the se
Like most things in Clojure, fields in types defined via deftype
are immutable. While you can circumvent this using :volatile-mutable
/ :unsynchronized-mutable
annotations, it is not common at all to do so. For one thing, such annotations will make the field private, so only the methods defined on the type will be able to access (and thus set) it. But more importantly, such constructs are susceptible to data races.
When mutability is required, idomatic Clojure will use one of Clojure's reference types like atom or ref.