unifying introductory functions a bit
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
(meditations
|
||||
"Your will face many decisions"
|
||||
"You will face many decisions"
|
||||
(= __ (if (false? (= 4 5)) :a :b))
|
||||
|
||||
"Some of them leave you no alternative"
|
||||
(= __ (if (> 4 3) []))
|
||||
|
||||
"And in such a case you may have nothing"
|
||||
(= nil (if (nil? __) [:a :b :c])))
|
||||
(= nil (if (nil? __) [:a :b :c]))
|
||||
|
||||
"In others your alternative may be interesting"
|
||||
(= :glory (if (not (empty? ())) :doom __))
|
||||
|
||||
"Or your fate may be sealed"
|
||||
(= __ (if-not (zero? __) 'doom 'doom)))
|
||||
|
||||
|
@@ -1,19 +1,19 @@
|
||||
(defn count-items [& items]
|
||||
(count items))
|
||||
(defn raise-to-the-tenth-power [n]
|
||||
(Math/pow n 10))
|
||||
|
||||
(meditations
|
||||
"Functions are often defined before they are used"
|
||||
(= __ (count-items :a :b :c :d))
|
||||
(= __ (raise-to-the-tenth-power 2))
|
||||
|
||||
"But they can also be defined inline"
|
||||
(= __ ((fn [n] (Math/pow n 10)) 2))
|
||||
(= __ ((fn [n] (Math/pow n __)) 2))
|
||||
|
||||
"Or using even shorter syntax"
|
||||
(= __ (#(Math/pow % 10)))
|
||||
(= __ (#(Math/pow % 10) __))
|
||||
|
||||
"Functions can beget others"
|
||||
"One function can beget another"
|
||||
(= __ (((fn []
|
||||
(fn [a b] (+ a b))))
|
||||
(fn [a b] __ a b)))
|
||||
4 5))
|
||||
|
||||
"Higher-order functions take function arguments"
|
||||
|
Reference in New Issue
Block a user