Skip to content

Instantly share code, notes, and snippets.

@msgodf
Created May 20, 2013 11:24
Show Gist options
  • Save msgodf/5611697 to your computer and use it in GitHub Desktop.
Save msgodf/5611697 to your computer and use it in GitHub Desktop.
Messing around with Clojure agents
; 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