Add some background knowledge to the recursion section.
This commit is contained in:
@@ -1,7 +1,25 @@
|
||||
(defn is-even? [n]
|
||||
(if (= n 0) __
|
||||
(___ (is-even? (dec n)))))
|
||||
|
||||
(defn is-even-bigint? [n]
|
||||
(loop [n n acc true]
|
||||
(if (= n 0) __
|
||||
(recur (dec n) (not acc)))))
|
||||
|
||||
(defn factorial [n]
|
||||
__)
|
||||
|
||||
(meditations
|
||||
"Recursion ends with a base case"
|
||||
(= true (is-even? 0))
|
||||
|
||||
"And starts by moving toward that base case"
|
||||
(= false (is-even? 1))
|
||||
|
||||
"Having too many stack frames requires explicit tail calls with recur"
|
||||
(= false (is-even-bigint? 100003N))
|
||||
|
||||
"Simple things may appear simple."
|
||||
(= 1 (factorial 1))
|
||||
|
||||
|
Reference in New Issue
Block a user