更新原子值
有两个命令来改变原子,swap! 和 reset!。swap! 被赋予命令,并根据其当前状态改变原子。reset! 完全改变原子的值,无论原子的值是多少:
(swap! counter inc) ; => 1
(reset! counter 0) ; => 0
这个例子使用原子输出 2 的前 10 个幂:
(def count (atom 0))
(while (< @atom 10)
(swap! atom inc)
(println (Math/pow 2 @atom)))