Skip to content

Commit

Permalink
Reformatting for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Oct 26, 2011
1 parent dd23270 commit 3cca560
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/koans/atoms.clj
Expand Up @@ -27,5 +27,4 @@
"When your expectations are aligned with reality things, proceed that way" "When your expectations are aligned with reality things, proceed that way"
(= :fin (do (= :fin (do
(compare-and-set! __ __ __) (compare-and-set! __ __ __)
@atomic-clock)) @atomic-clock)))
)
17 changes: 8 additions & 9 deletions src/koans/conditionals.clj
Expand Up @@ -10,21 +10,21 @@
(meditations (meditations
"You will face many decisions" "You will face many decisions"
(= __ (if (false? (= 4 5)) (= __ (if (false? (= 4 5))
:a :a
:b)) :b))


"Some of them leave you no alternative" "Some of them leave you no alternative"
(= __ (if (> 4 3) (= __ (if (> 4 3)
[])) []))


"And in such a situation you may have nothing" "And in such a situation you may have nothing"
(= __ (if (nil? 0) (= __ (if (nil? 0)
[:a :b :c])) [:a :b :c]))


"In others your alternative may be interesting" "In others your alternative may be interesting"
(= :glory (if (not (empty? ())) (= :glory (if (not (empty? ()))
:doom :doom
__)) __))


"You may have a multitude of possible paths" "You may have a multitude of possible paths"
(let [x 5] (let [x 5]
Expand All @@ -34,8 +34,8 @@


"Or your fate may be sealed" "Or your fate may be sealed"
(= __ (if-not (zero? __) (= __ (if-not (zero? __)
'doom 'doom
'doom)) 'doom))


"In case of emergency, sound the alarms" "In case of emergency, sound the alarms"
(= :sirens (= :sirens
Expand All @@ -44,4 +44,3 @@
"But admit it when you don't know what to do" "But admit it when you don't know what to do"
(= __ (= __
(explain-defcon-level :yo-mama))) (explain-defcon-level :yo-mama)))

12 changes: 5 additions & 7 deletions src/koans/creating_functions.clj
@@ -1,24 +1,23 @@
(defn square [x] (* x x)) (defn square [x] (* x x))


(meditations (meditations

"One may know what they seek by knowing what they do not seek" "One may know what they seek by knowing what they do not seek"
(= [__ __ __] (let [not-a-symbol? (complement symbol?)] (= [__ __ __] (let [not-a-symbol? (complement symbol?)]
(map not-a-symbol? [:a 'b "c"]))) (map not-a-symbol? [:a 'b "c"])))


"Praise and 'complement' may help you separate the wheat from the chaff" "Praise and 'complement' may help you separate the wheat from the chaff"
(= [:wheat "wheat" 'wheat] (= [:wheat "wheat" 'wheat]
(let [not-nil? ___] (let [not-nil? ___]
(filter not-nil? [nil :wheat nil "wheat" nil 'wheat nil]))) (filter not-nil? [nil :wheat nil "wheat" nil 'wheat nil])))


"Partial functions allow procrastination" "Partial functions allow procrastination"
(= 20 (let [multiply-by-5 (partial * 5)] (= 20 (let [multiply-by-5 (partial * 5)]
(___ __))) (___ __)))


"Don't forget: first things first" "Don't forget: first things first"
(= [__ __ __ __] (= [__ __ __ __]
(let [ab-adder (partial concat [:a :b])] (let [ab-adder (partial concat [:a :b])]
(ab-adder [__ __]))) (ab-adder [__ __])))


"Functions can join forces as one 'composed' function" "Functions can join forces as one 'composed' function"
(= 25 (let [inc-and-square (comp square inc)] (= 25 (let [inc-and-square (comp square inc)]
Expand All @@ -30,5 +29,4 @@


"Be careful about the order in which you mix your functions" "Be careful about the order in which you mix your functions"
(= 99 (let [square-and-dec ___] (= 99 (let [square-and-dec ___]
(square-and-dec 10)))) (square-and-dec 10))))

1 change: 0 additions & 1 deletion src/koans/datatypes.clj
Expand Up @@ -42,4 +42,3 @@
"Surely we can implement our own by now" "Surely we can implement our own by now"
(= "You're really the Worst Picture, Final Destination 5... sorry." (= "You're really the Worst Picture, Final Destination 5... sorry."
(with-out-str (present (Razzie. "Worst Picture") "Final Destination 5")))) (with-out-str (present (Razzie. "Worst Picture") "Final Destination 5"))))

13 changes: 6 additions & 7 deletions src/koans/destructuring.clj
Expand Up @@ -6,19 +6,19 @@
(meditations (meditations
"Destructuring is an arbiter: it breaks up arguments" "Destructuring is an arbiter: it breaks up arguments"
(= __ ((fn [[a b]] (str b a)) (= __ ((fn [[a b]] (str b a))
[:foo :bar])) [:foo :bar]))


"Whether in function definitions" "Whether in function definitions"
(= (str "First comes love, " (= (str "First comes love, "
"then comes marriage, " "then comes marriage, "
"then comes Clojure with the baby carriage") "then comes Clojure with the baby carriage")
((fn [[a b c]] __) ((fn [[a b c]] __)
["love" "marriage" "Clojure"])) ["love" "marriage" "Clojure"]))


"Or in let expressions" "Or in let expressions"
(= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah" (= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah"
(let [[first-name last-name & aliases] (let [[first-name last-name & aliases]
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Macro Killah")] (list "Rich" "Hickey" "The Clojurer" "Go Time" "Macro Killah")]
__)) __))


"You can regain the full argument if you like arguing" "You can regain the full argument if you like arguing"
Expand All @@ -29,14 +29,13 @@
"Break up maps by key" "Break up maps by key"
(= "123 Test Lane, Testerville, TX" (= "123 Test Lane, Testerville, TX"
(let [{street-address :street-address, city :city, state :state} test-address] (let [{street-address :street-address, city :city, state :state} test-address]
__)) __))


"Or more succinctly" "Or more succinctly"
(= "123 Test Lane, Testerville, TX" (= "123 Test Lane, Testerville, TX"
(let [{:keys [street-address __ __]} test-address] (let [{:keys [street-address __ __]} test-address]
__)) __))


"All together now!" "All together now!"
(= "Test Testerson, 123 Test Lane, Testerville, TX" (= "Test Testerson, 123 Test Lane, Testerville, TX"
(___ ["Test" "Testerson"] test-address)) (___ ["Test" "Testerson"] test-address)))
)
6 changes: 3 additions & 3 deletions src/koans/functions.clj
Expand Up @@ -18,12 +18,12 @@


"One function can beget another" "One function can beget another"
(= __ ((fn [] (= __ ((fn []
((fn [a b] (__ a b)) ((fn [a b] (__ a b))
4 5)))) 4 5))))


"Higher-order functions take function arguments" "Higher-order functions take function arguments"
(= 25 (___ (= 25 (___
(fn [n] (* n n)))) (fn [n] (* n n))))


"But they are often better written using the names of functions" "But they are often better written using the names of functions"
(= 25 (___ square))) (= 25 (___ square)))
18 changes: 8 additions & 10 deletions src/koans/macros.clj
Expand Up @@ -11,17 +11,16 @@


(defmacro r-infix [form] (defmacro r-infix [form]
(cond (not (seq? form)) (cond (not (seq? form))
__ __
(= 1 (count form)) (= 1 (count form))
`(r-infix ~(first form)) `(r-infix ~(first form))
:else :else
(let [operator (second form) (let [operator (second form)
first-arg (first form) first-arg (first form)
others __] others __]
`(~operator `(~operator
(r-infix ~first-arg) (r-infix ~first-arg)
(r-infix ~others))))) (r-infix ~others)))))



(meditations (meditations
"Macros are like functions created at compile time" "Macros are like functions created at compile time"
Expand All @@ -41,4 +40,3 @@


"Really, you dont understand recursion until you understand recursion" "Really, you dont understand recursion until you understand recursion"
(= 36 (r-infix (10 + (2 * 3) + (4 * 5))))) (= 36 (r-infix (10 + (2 * 3) + (4 * 5)))))

1 change: 0 additions & 1 deletion src/koans/maps.clj
Expand Up @@ -48,4 +48,3 @@
"Or the values" "Or the values"
(= (list "Sochi" "Torino" __) (= (list "Sochi" "Torino" __)
(sort (vals {2006 "Torino" 2010 "Vancouver" 2014 "Sochi"})))) (sort (vals {2006 "Torino" 2010 "Vancouver" 2014 "Sochi"}))))

8 changes: 4 additions & 4 deletions src/koans/recursion.clj
@@ -1,14 +1,14 @@
(defn is-even? [n] (defn is-even? [n]
(if (= n 0) (if (= n 0)
__ __
(___ (is-even? (dec n))))) (___ (is-even? (dec n)))))


(defn is-even-bigint? [n] (defn is-even-bigint? [n]
(loop [n n (loop [n n
acc true] acc true]
(if (= n 0) (if (= n 0)
__ __
(recur (dec n) (not acc))))) (recur (dec n) (not acc)))))


(defn recursive-reverse [coll] (defn recursive-reverse [coll]
__) __)
Expand Down
21 changes: 10 additions & 11 deletions src/koans/refs.clj
Expand Up @@ -16,25 +16,24 @@
"Alter where you need not replace" "Alter where you need not replace"
(= __ (let [exclamator (fn [x] (str x "!"))] (= __ (let [exclamator (fn [x] (str x "!"))]
(dosync (dosync
(alter the-world exclamator) (alter the-world exclamator)
(alter the-world exclamator) (alter the-world exclamator)
(alter the-world exclamator)) (alter the-world exclamator))
@the-world)) @the-world))


"Don't forget to do your work in a transaction!" "Don't forget to do your work in a transaction!"
(= 0 (do __ (= 0 (do __
@the-world)) @the-world))


"Functions passed to alter may depend on the data in the ref" "Functions passed to alter may depend on the data in the ref"
(= 20 (do (= 20 (do
(dosync (alter the-world ___)))) (dosync (alter the-world ___))))


"Two worlds are better than one" "Two worlds are better than one"
(= ["Real Jerry" "Bizarro Jerry"] (= ["Real Jerry" "Bizarro Jerry"]
(do (do
(dosync (dosync
(ref-set the-world {}) (ref-set the-world {})
(alter the-world assoc :jerry "Real Jerry") (alter the-world assoc :jerry "Real Jerry")
(alter bizarro-world assoc :jerry "Bizarro Jerry") (alter bizarro-world assoc :jerry "Bizarro Jerry")
__)))) __))))

4 changes: 2 additions & 2 deletions src/koans/sequence_comprehensions.clj
Expand Up @@ -28,5 +28,5 @@
(= [[:top :left] [:top :middle] [:top :right] (= [[:top :left] [:top :middle] [:top :right]
[:middle :left] [:middle :middle] [:middle :right] [:middle :left] [:middle :middle] [:middle :right]
[:bottom :left] [:bottom :middle] [:bottom :right]] [:bottom :left] [:bottom :middle] [:bottom :right]]
(for [row [:top :middle :bottom] column [:left :middle :right]] (for [row [:top :middle :bottom] column [:left :middle :right]]
__))) __)))
1 change: 0 additions & 1 deletion src/koans/sets.clj
Expand Up @@ -16,4 +16,3 @@


"But don't forget about the difference" "But don't forget about the difference"
(= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5}))) (= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5})))

0 comments on commit 3cca560

Please sign in to comment.