2015-09-13 05:28:39 +00:00
|
|
|
(ns koans.17-atoms
|
2014-05-02 21:37:11 +00:00
|
|
|
(:require [koan-engine.core :refer :all]))
|
2014-01-26 00:04:22 +00:00
|
|
|
|
2011-03-31 12:44:54 +00:00
|
|
|
(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))
|
|
|
|
|
2014-01-09 01:14:08 +00:00
|
|
|
"When your expectations are aligned with reality, things proceed that way"
|
2011-03-31 12:44:54 +00:00
|
|
|
(= :fin (do
|
|
|
|
(compare-and-set! __ __ __)
|
2011-10-26 02:55:54 +00:00
|
|
|
@atomic-clock)))
|