Refs. We has them.

This commit is contained in:
Colin Jones 2010-11-09 20:19:10 -06:00
parent d696a9c76f
commit a8dc9b36bb
3 changed files with 35 additions and 1 deletions

27
src/koans/refs.clj Normal file
View File

@ -0,0 +1,27 @@
(def the-world (ref "hello"))
(meditations
"In the beginning, there was a word"
(= __ (deref the-world))
"You can get the word more succinctly, but it's the same"
(= __ @the-world)
"You can be the change you wish to see in the world."
(= __ (do
(dosync (ref-set the-world "better"))
@the-world))
"Alter where you need not replace"
(= __ (let [exclamator (fn [x] (str x "!"))]
(dosync
(alter the-world exclamator)
(alter the-world exclamator)
(alter the-world exclamator))
@the-world))
"Though you should keep transactions as short as possible"
(= "better!!!!!!" (letfn [(exclamator [x] (str x "!"))]
(dosync
(alter the-world ___))
@the-world)))

View File

@ -111,6 +111,12 @@
(repeat " "))))
'{:original-parts full-name
:named-parts {:first first-name :last last-name}} ]}
"refs" {"__" ["\"hello\""
"\"hello\""
"\"better\""
"\"better!!!\""
]
"___" ['(comp exclamator exclamator exclamator)]}
})
(defn replace-with [s k replacements]

View File

@ -27,7 +27,8 @@
"sequence_comprehensions"
"partial_functions"
"recursion"
"destructuring"])
"destructuring"
"refs"])
(defn run []
(apply load (doall (map (partial str "koans/") ordered-koans)))