14-15
This commit is contained in:
parent
3c92967e74
commit
db99c57eb1
2 changed files with 24 additions and 14 deletions
|
|
@ -3,21 +3,29 @@
|
||||||
|
|
||||||
(defn is-even? [n]
|
(defn is-even? [n]
|
||||||
(if (= n 0)
|
(if (= n 0)
|
||||||
__
|
true
|
||||||
(___ (is-even? (dec n)))))
|
(not (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)
|
||||||
__
|
false
|
||||||
(recur (dec n) (not acc)))))
|
(recur (dec n) (not acc)))))
|
||||||
|
|
||||||
(defn recursive-reverse [coll]
|
(defn recursive-reverse [coll]
|
||||||
__)
|
(loop [coll coll
|
||||||
|
reversed '()]
|
||||||
|
(if (empty? coll)
|
||||||
|
reversed
|
||||||
|
(recur (rest coll) (cons (first coll) reversed)))))
|
||||||
|
|
||||||
(defn factorial [n]
|
(defn factorial [n]
|
||||||
__)
|
(loop [n n
|
||||||
|
res 1]
|
||||||
|
(if (= 0 n)
|
||||||
|
res
|
||||||
|
(recur (dec n) (* n res)))))
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"Recursion ends with a base case"
|
"Recursion ends with a base case"
|
||||||
|
|
|
||||||
|
|
@ -8,37 +8,39 @@
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"Destructuring is an arbiter: it breaks up arguments"
|
"Destructuring is an arbiter: it breaks up arguments"
|
||||||
(= __ ((fn [[a b]] (str b a))
|
(= ":bar:foo" ((fn [[a b]] (str b a))[:foo :bar]))
|
||||||
[:foo :bar]))
|
|
||||||
|
|
||||||
"Whether in function definitions"
|
"Whether in function definitions"
|
||||||
(= (str "An Oxford comma list of apples, "
|
(= (str "An Oxford comma list of apples, "
|
||||||
"oranges, "
|
"oranges, "
|
||||||
"and pears.")
|
"and pears.")
|
||||||
((fn [[a b c]] __)
|
((fn [[a b c]] (str "An Oxford comma list of " a ", " b ", and " c "."))
|
||||||
["apples" "oranges" "pears"]))
|
["apples" "oranges" "pears"]))
|
||||||
|
|
||||||
"Or in let expressions"
|
"Or in let expressions"
|
||||||
(= "Rich Hickey aka The Clojurer aka Go Time aka Lambda Guru"
|
(= "Rich Hickey aka The Clojurer aka Go Time aka Lambda Guru"
|
||||||
(let [[first-name last-name & aliases]
|
(let [[first-name last-name & aliases]
|
||||||
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
|
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
|
||||||
__))
|
(apply str (interpose " aka " (cons (str first-name " " last-name) aliases)))))
|
||||||
|
|
||||||
"You can regain the full argument if you like arguing"
|
"You can regain the full argument if you like arguing"
|
||||||
(= {:original-parts ["Stephen" "Hawking"] :named-parts {:first "Stephen" :last "Hawking"}}
|
(= {:original-parts ["Stephen" "Hawking"] :named-parts {:first "Stephen" :last "Hawking"}}
|
||||||
(let [[first-name last-name :as full-name] ["Stephen" "Hawking"]]
|
(let [[first-name last-name :as full-name] ["Stephen" "Hawking"]]
|
||||||
__))
|
(hash-map :original-parts full-name :named-parts (hash-map :first first-name :last last-name))))
|
||||||
|
|
||||||
"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]
|
||||||
__))
|
(apply str (interpose ", " (list street-address city state)))))
|
||||||
|
|
||||||
"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 city state]} test-address]
|
||||||
__))
|
(apply str (interpose ", " (list street-address city state)))))
|
||||||
|
|
||||||
"All together now!"
|
"All together now!"
|
||||||
(= "Test Testerson, 123 Test Lane, Testerville, TX"
|
(= "Test Testerson, 123 Test Lane, Testerville, TX"
|
||||||
(___ ["Test" "Testerson"] test-address)))
|
((fn [[a b] {:keys [street-address city state]}]
|
||||||
|
(apply str (interpose ", " (list (str a " " b) street-address city state))))
|
||||||
|
|
||||||
|
["Test" "Testerson"] test-address))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue