Created
May 20, 2013 11:24
-
-
Save msgodf/5611697 to your computer and use it in GitHub Desktop.
Messing around with Clojure agents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; A little function that adds its two parameters together | |
(defn addit [x y] (+ x y)) | |
; This adds the value supplied in the second parameter to the atom in the first parameter, then returns the atom | |
(defn atom-adder [x y] (swap! x (partial addit y)) x) | |
(def value-atom (atom 1)) | |
; Create an agent with a reference to the atom | |
(def counter-agent (agent value-atom)) | |
; Send an action to the agent to add the supplied value to the atom to which it has a reference | |
(send-off counter-agent atom-adder 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment