From a7f7df6f016ca887d4b7ee7953366ac6b8f1827c Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Wed, 10 Nov 2010 19:16:50 -0600 Subject: [PATCH] Get users to write ref mutations themselves. --- src/koans/refs.clj | 10 +++++++++- src/path_to_answer_sheet.clj | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/koans/refs.clj b/src/koans/refs.clj index 1d57cb9..2a4a522 100644 --- a/src/koans/refs.clj +++ b/src/koans/refs.clj @@ -24,4 +24,12 @@ (= "better!!!!!!" (letfn [(exclamator [x] (str x "!"))] (dosync (alter the-world ___)) - @the-world))) + @the-world)) + + "Don't forget to do your work in a transaction!" + (= 0 (do __ + @the-world)) + + "Functions passed to alter may depend on the data in the ref" + (= 20 (do + (dosync (alter the-world ___))))) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index 8f382d6..0daff8b 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -115,8 +115,11 @@ "\"hello\"" "\"better\"" "\"better!!!\"" + '(dosync (ref-set the-world 0)) + ] - "___" ['(comp exclamator exclamator exclamator)]} + "___" ['(comp exclamator exclamator exclamator) + '(fn [x] (+ 20 x))]} }) (defn replace-with [s k replacements]