I'm just reliving Clojure Coans, and now I'm playing with atoms. My question is not related to Coan, but a general one.
Consider the following (abbreviated) example from Koans:
(def atomic-clock (atom 0)) (meditations (= 1 (do (swap! atomic-clock inc) @atomic-clock)))
Documentation for sharing! that the function that it applies to ( inc in this case) can be called several times, and therefore the function should be free of side effects.
Obviously, inc has no side effects, but is not idempotent. Does this mean that the above statement may actually still not work? That is, what if the function is actually called several times, the value of the atom increases more than once?
source share