Skip to content

Commit

Permalink
Harnessing the Power of Flow Control
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hyungu committed Dec 9, 2015
1 parent d43cbea commit 540b3dc
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/wonderland/chapter_2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,88 @@
(some #{nil} [nil nil nil])
(some #{false} [false false false])
(some #{true} [true true true])

; Harnessing the Power of Flow Control
(if true "it is true" "it is false")
(if false "it is true" "it is false")
(if nil "it is true" "it is false")
(if (= :drinkme :drinkme)
"Try it"
"Don't try it")

(let [need-to-grow-small (> 5 3)]
(if need-to-grow-small
"drink bottle"
"don't drink bottle"))

(if-let [need-to-grow-small (> 5 1)]
"drink bottle"
"don't drink bottle")

(defn drink [need-to-grow-small]
(when need-to-grow-small "drink bottle"))

(drink true)
(drink false)

(when-let [need-to-grow-small true]
"drink bottle")
(when-let [need-to-grow-small false]
"drink bottle")

(let [bottle "drinkme"]
(cond
(= bottle "poison") "don't touch"
(= bottle "drinkme") "grow smaller"
(= bottle "empty") "all gone"))

(let [x 5]
(cond
(> x 10) "bigger than 10"
(> x 4) "bigger than 4"
(> x 3) "bigger than 3"))

(let [x 5]
(cond
(> x 3) "bigger than 3"
(> x 10) "bigger than 10"
(> x 4) "bigger than 4"))

(let [x 1]
(cond
(> x 10) "bigger than 10"
(> x 4) "bigger than 4"
(> x 3) "bigger than 3"))

(let [bottle "mystery"]
(cond
(= bottle "poison") "don't touch"
(= bottle "drinkme") "grow smaller"
(= bottle "empty") "all gone"
:else "unknown"))

(let [bottle "mystery"]
(cond
(= bottle "poison") "don't touch"
(= bottle "drinkme") "grow smaller"
(= bottle "empty") "all gone"
"default" "unknown"))

(let [bottle "drinkme"]
(case bottle
"poison" "don't touch"
"drinkme" "grow smaller"
"empty" "all gone"))

(let [bottle "mystery"]
(case bottle
"poison" "don't touch"
"drinkme" "grow smaller"
"empty" "all gone"))

(let [bottle "mystery"]
(case bottle
"poison" "don't touch"
"drinkme" "grow smaller"
"empty" "all gone"
"unknown"))

0 comments on commit 540b3dc

Please sign in to comment.