split the application essential state in discrete «boxes» • Changing the state split later on is not painless. • I just want to put the world in a single box!
400})) (defn transfer [amount] (fn [from to] [(- from amount) (+ to amount)])) ;; No retry of the transfer fn! (swap-ins! accounts (transfer 50) [:ricky] [:lucy]) (swap-ins! accounts (transfer 20) [:ethel] [:fred])
single root ref • Fixed number (N) of guards (refs) • To perform actions (ensure, ref-set/alter, commute) on the item ith • perform dummy actions on the (i mod N)th guard! • deref or commute the root ref!
to cells -(def world - (apply vector - (map (fn [_] - (apply vector (map (fn [_] (ref (struct cell 0 0))) - (range dim)))) - (range dim)))) +;world is a megaref to a 2d vector of cells +(def world + (megaref (vec (repeat dim (vec (repeat dim (struct cell 0 0))))))) -(defn place [[x y]] - (-> world (nth x) (nth y))) +(defn place [xy] + (subref world xy))
single root atom • Fixed number (N) of guards (agents) • To perform send f on the item ith • send (fn [_] (swap! root assoc-in [i] (f (get-in path @root)))) to the (i mod N)th guard!