Problems with Immutable Data in Functional Programming
I can provide an answer for the clojure
case. In clojure
, if you need to co-ordinate access to shared state, there are constructs in the language that are designed to deal with these situations.
In this case, you could use an atom
to hold the value. Changes made to an atom
are atomic, and will be made optimistically by way of clojure's STM. Atoms are one of clojure's reference types. An atom is essentially a reference to a value, which can change over time in a controlled way via the atom's mutation functions.
See the clojure docs for more information on atoms and the other references types.