Some cleanup & adding a better-syntax of the function toughie.

This commit is contained in:
Colin Jones 2010-11-02 22:29:45 -05:00
parent 2841228b07
commit 87e25afc1e
4 changed files with 21 additions and 8 deletions

View File

@ -7,7 +7,6 @@ lazy sequences
recursion recursion
recursive list processing recursive list processing
trampolining trampolining
currying / pfa
reflection reflection
Destructuring Destructuring
Metadata Metadata

View File

@ -1,16 +1,24 @@
(meditations (meditations
"You will face many decisions" "You will face many decisions"
(= __ (if (false? (= 4 5)) :a :b)) (= __ (if (false? (= 4 5))
:a
: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 case you may have nothing" "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" "In others your alternative may be interesting"
(= :glory (if (not (empty? ())) :doom __)) (= :glory (if (not (empty? ()))
:doom
__))
"Or your fate may be sealed" "Or your fate may be sealed"
(= __ (if-not (zero? __) 'doom 'doom))) (= __ (if-not (zero? __)
'doom
'doom)))

View File

@ -1,6 +1,8 @@
(defn multiply-by-ten [n] (defn multiply-by-ten [n]
(* 10 n)) (* 10 n))
(defn square [n] (* n n))
(meditations (meditations
"Functions are often defined before they are used" "Functions are often defined before they are used"
(= __ (multiply-by-ten 2)) (= __ (multiply-by-ten 2))
@ -18,4 +20,7 @@
"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"
(= 25 (___ square)))

View File

@ -54,7 +54,8 @@
10 5 10 5
30 2 30 2
20 "*"] 20 "*"]
"___" ["(fn [f] (f 5))"]} "___" ["(fn [f] (f 5))"
"(fn [f] 25)"]}
"conditionals" {"__" [:a "conditionals" {"__" [:a
[] []
0 0