I am considering using Clojure records to map to changing entities in my program. Are they mutable? Or do you need to use extra refs within the records? I am a little confused about this
I am considering using Clojure records to map to changing entities in my program.
Share
It’s well worth watching Rich Hickey’s fantastic video on identity and state.
Records are designed to be immutable and store the state of something as a value.
To model the state of a changing entity, I’d recommend using a ref that refers to an immutable value that represents the current state. You can use records for the immutable state, but often it’s simpler just to use a simple map.
A simple example, where the mutable state is a scoreboard for a game: