Permalink
Browse files

Merge pull request #56 from suzaku/master

Show more idiomatic usage of swap!
  • Loading branch information...
2 parents 77f1945 + d9ddc47 commit b61957fdbbd82a09a129a164c9108fc55c64031d Michael Klishin committed Nov 18, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 articles/language/concurrency_and_parallelism.md
View
9 articles/language/concurrency_and_parallelism.md
@@ -284,11 +284,14 @@ Locals can be atoms, too:
;; ⇒ []
```
-Now to the most interesting part: adding elements to the collection. To mutate an atom, use `clojure.core/swap!`
-which takes an atom and a function that takes the current value of the atom and must return a new value:
+Now to the most interesting part: adding elements to the collection.
+
+To mutate an atom, we can use `clojure.core/swap!`.
+
+`swap!` takes an atom, a function and optionally some other args, swaps the current value of the atom to be the return value of calling the function with the current value of the atom and the args:
``` clojure
-(swap! currently-connected (fn [xs] (conj xs "chatty-joe")))
+(swap! currently-connected conj "chatty-joe")
;; ⇒ ["chatty-joe"]
currently-connected
;; ⇒ #<Atom@614b6b5d: ["chatty-joe"]>

0 comments on commit b61957f

Please sign in to comment.