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"
(= :fin (do
(compare-and-set! __ __ __)
@atomic-clock))
)
@atomic-clock)))
17 changes: 8 additions & 9 deletions src/koans/conditionals.clj
Expand Up @@ -10,21 +10,21 @@
(meditations
"You will face many decisions"
(= __ (if (false? (= 4 5))
:a
:b))
:a
:b))

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

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

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

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

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

"In case of emergency, sound the alarms"
(= :sirens
Expand All @@ -44,4 +44,3 @@
"But admit it when you don't know what to do"
(= __
(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))

(meditations

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

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

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

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

"Functions can join forces as one 'composed' function"
(= 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"
(= 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"
(= "You're really the Worst Picture, Final Destination 5... sorry."
(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
"Destructuring is an arbiter: it breaks up arguments"
(= __ ((fn [[a b]] (str b a))
[:foo :bar]))
[:foo :bar]))

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

"Or in let expressions"
(= "Rich Hickey aka The Clojurer aka Go Time aka Macro Killah"
(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"
Expand All @@ -29,14 +29,13 @@
"Break up maps by key"
(= "123 Test Lane, Testerville, TX"
(let [{street-address :street-address, city :city, state :state} test-address]
__))
__))

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

"All together now!"
(= "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"
(= __ ((fn []
((fn [a b] (__ a b))
4 5))))
((fn [a b] (__ a b))
4 5))))

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

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

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

(let [operator (second form)
first-arg (first form)
others __]
`(~operator
(r-infix ~first-arg)
(r-infix ~others)))))

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

"Really, you dont understand recursion until you understand recursion"
(= 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"
(= (list "Sochi" "Torino" __)
(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]
(if (= n 0)
__
(___ (is-even? (dec n)))))
__
(___ (is-even? (dec n)))))

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

(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"
(= __ (let [exclamator (fn [x] (str x "!"))]
(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))

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

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

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

(do
(dosync
(ref-set the-world {})
(alter the-world assoc :jerry "Real 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]
[:middle :left] [:middle :middle] [:middle :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"
(= __ (clojure.set/difference #{1 2 3 4 5} #{2 3 5})))

0 comments on commit 3cca560

Please sign in to comment.