clojure-koans/src/koans/16_atoms.clj
Colin Jones 78c5704f34 Rename to use underscores instead of dashes
Works fine either way - this is just since underscores are required
in filenames for real projects, so it's something good for folks to
get used to.
2012-06-08 15:22:42 -05:00

31 lines
725 B
Clojure

(def atomic-clock (atom 0))
(meditations
"Atoms are like refs"
(= __ @atomic-clock)
"You can change at the swap meet"
(= __ (do
(swap! atomic-clock inc)
@atomic-clock))
"Keep taxes out of this: swapping requires no transaction"
(= 5 (do
__
@atomic-clock))
"Any number of arguments might happen during a swap"
(= __ (do
(swap! atomic-clock + 1 2 3 4 5)
@atomic-clock))
"Atomic atoms are atomic"
(= __ (do
(compare-and-set! atomic-clock 100 :fin)
@atomic-clock))
"When your expectations are aligned with reality things, proceed that way"
(= :fin (do
(compare-and-set! __ __ __)
@atomic-clock)))