There are two commands to change an atom, swap!
and reset!
. swap!
is given commands, and changes the atom based on its current state. reset!
changes the atom's value completely, regardless of what the original atom's value was:
(swap! counter inc) ; => 1
(reset! counter 0) ; => 0
This example outputs the first 10 powers of 2
using atoms:
(def count (atom 0))
(while (< @atom 10)
(swap! atom inc)
(println (Math/pow 2 @atom)))