diff --git a/ideaboard.txt b/ideaboard.txt index 44b330d..d72823f 100644 --- a/ideaboard.txt +++ b/ideaboard.txt @@ -1,7 +1,6 @@ Concepts / Language Features ===== Agents -Atoms Vars state identity lifetime lazy sequences diff --git a/src/koans/atoms.clj b/src/koans/atoms.clj new file mode 100644 index 0000000..dbadb66 --- /dev/null +++ b/src/koans/atoms.clj @@ -0,0 +1,31 @@ +(def atomic-clock (atom 0)) + +(meditations + "Atoms are like refs" + (= __ @atomic-clock) + + "You can change at the swap meet" + (= __ (do + (swap! atomic-clock inc) + @atomic-clock)) + + "Keep taxes out of this: swapping requires no transaction" + (= 5 (do + __ + @atomic-clock)) + + "Any number of arguments might happen during a swap" + (= __ (do + (swap! atomic-clock + 1 2 3 4 5) + @atomic-clock)) + + "Atomic atoms are atomic" + (= __ (do + (compare-and-set! atomic-clock 100 :fin) + @atomic-clock)) + + "When your expectations are aligned with reality things, proceed that way" + (= :fin (do + (compare-and-set! __ __ __) + @atomic-clock)) + ) diff --git a/src/path_to_answer_sheet.clj b/src/path_to_answer_sheet.clj index b46236c..ff63017 100644 --- a/src/path_to_answer_sheet.clj +++ b/src/path_to_answer_sheet.clj @@ -144,6 +144,14 @@ ] "___" ['(fn [x] (+ 20 x))]} + "atoms" {"__" [0 + 1 + '(swap! atomic-clock (partial + 4)) + 20 + 20 + 'atomic-clock 20 :fin + ]} + "macros" {"__" ['~(first form) '~(nth form 2) 'form diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index ecc1216..1f08cc9 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -34,6 +34,7 @@ "recursion" "destructuring" "refs" + "atoms" "macros" "datatypes"])