Transaktion mit Nebenwirkung

Transaktionen:
(def base 100)
(def source (ref (* base base)))
(def target (ref 0))
(defn move [foo]
   (dotimes [x base]
      (dosync (ref-set source (- @source 1))
	      (ref-set target (+ @target 1))) ))
(def movers (for [x (range 1 base)] (agent nil)))
(dorun (map #(send-off % move) movers))
Nebenwirkung einbauen:
(def c (atom 0)) ... (swap! c inc) ... 
(printf c)



Johannes Waldmann 2011-06-29