Reformatting for consistency
This commit is contained in:
parent
dd232703af
commit
3cca560b96
@ -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)))
|
||||||
)
|
|
||||||
|
@ -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]
|
||||||
@ -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
|
||||||
@ -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)))
|
||||||
|
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
(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)]
|
||||||
@ -17,8 +16,8 @@
|
|||||||
|
|
||||||
"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)]
|
||||||
@ -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))))
|
||||||
|
|
||||||
|
@ -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"))))
|
||||||
|
|
||||||
|
@ -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"
|
||||||
@ -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)))
|
||||||
)
|
|
||||||
|
@ -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)))
|
||||||
|
@ -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"
|
||||||
@ -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)))))
|
||||||
|
|
||||||
|
@ -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"}))))
|
||||||
|
|
||||||
|
@ -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]
|
||||||
__)
|
__)
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
"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
|
||||||
@ -31,10 +31,9 @@
|
|||||||
|
|
||||||
"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")
|
||||||
__))))
|
__))))
|
||||||
|
|
||||||
|
@ -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]]
|
||||||
__)))
|
__)))
|
||||||
|
@ -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})))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user