From 12a5b7aaec8bea74e25a9b3ed87eee3385b9c899 Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Thu, 24 Nov 2022 20:22:08 +0000 Subject: [PATCH] Finished koan 16 --- src/koans/16_refs.clj | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/koans/16_refs.clj b/src/koans/16_refs.clj index 3395f29..27bb681 100644 --- a/src/koans/16_refs.clj +++ b/src/koans/16_refs.clj @@ -6,31 +6,33 @@ (meditations "In the beginning, there was a word" - (= __ (deref the-world)) + (= "hello" (deref the-world)) "You can get the word more succinctly, but it's the same" - (= __ @the-world) + (= "hello" @the-world) "You can be the change you wish to see in the world." - (= __ (do - (dosync (ref-set the-world "better")) + (= "better" + (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)) + (= "better!!!" + (let [exclamator (fn [x] (str x "!"))] + + (dosync (alter the-world exclamator) + (alter the-world exclamator) + (alter the-world exclamator)) + + @the-world)) "Don't forget to do your work in a transaction!" - (= 0 (do __ + (= 0 (do (dosync (ref-set the-world 0)) @the-world)) "Functions passed to alter may depend on the data in the ref" (= 20 (do - (dosync (alter the-world ___)))) + (dosync (alter the-world + 20)))) "Two worlds are better than one" (= ["Real Jerry" "Bizarro Jerry"] @@ -39,4 +41,4 @@ (ref-set the-world {}) (alter the-world assoc :jerry "Real Jerry") (alter bizarro-world assoc :jerry "Bizarro Jerry") - __)))) + print(map :jerry [@the-world @bizarro-world])))))