Should the function the Clojure swap! is applied to be idempotent?

Viewed 528

I am just going through Clojure Koans and I am now playing with atoms. My question is not related to Koans, but a general one.

Consider the following (shortened) example from Koans:

(def atomic-clock (atom 0))

(meditations
    (= 1 (do
        (swap! atomic-clock inc)
            @atomic-clock)))

The documentation for swap! states that the function it is applied to (inc in this case) could be called multiple times and thus the function should be free from side effect.

Obviously, inc is free from side effects, but is not idempotent. Does this mean, that the assertion above may actually still fail? I.e. that in the case the function is indeed called multiple times, the value of the atom is incremented more than once?

3 Answers
Related