From a8dc9b36bb1eab2506324d05cf0113914c98565c Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Tue, 9 Nov 2010 20:19:10 -0600 Subject: [PATCH] Refs. We has them. --- src/koans/refs.clj | 27 +++++++++++++++++++++++++++ src/path_to_answer_sheet.clj | 6 ++++++ src/path_to_enlightenment.clj | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/koans/refs.clj diff --git a/src/koans/refs.clj b/src/koans/refs.clj new file mode 100644 index 0000000..1d57cb9 --- /dev/null +++ b/src/koans/refs.clj @@ -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))) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 6bdb9dd..8f382d6 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -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] diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index 36df1a3..0475659 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -27,7 +27,8 @@ "sequence_comprehensions" "partial_functions" "recursion" - "destructuring"]) + "destructuring" + "refs"]) (defn run [] (apply load (doall (map (partial str "koans/") ordered-koans)))