clojure-koans/08_conditionals.clj

45 lines
1.3 KiB
Clojure
Raw Normal View History

(defn explain-exercise-velocity [exercise-term]
(case exercise-term
:ten-mph :pretty-fast
:watching-tv :not-so-fast))
; "You will face many decisions"
(= :a (if (false? (= 4 5))
2011-10-26 02:55:54 +00:00
:a
:b))
2010-02-09 23:37:22 +00:00
; "Some of them leave you no alternative"
(= [] (if (> 4 3) ;; J - This is the equivalent of an if statement without an else.
[])) ;; returns nil if false as seen below.
2010-02-09 23:37:22 +00:00
; "And in such a situation you may have nothing"
(= nil (if (nil? 0)
2011-10-26 02:55:54 +00:00
[:a :b :c]))
2010-05-07 02:56:43 +00:00
; "In others your alternative may be interesting"
(= :glory (if (not (empty? ()))
2011-10-26 02:55:54 +00:00
:doom
:glory))
2010-05-07 02:56:43 +00:00
; "You may have a multitude of possible paths"
2010-11-04 01:38:20 +00:00
(let [x 5]
(= :your-road (cond (= x 3) :road-not-taken
(= x 2) :another-road-not-taken
:else :your-road))) ;; J - The syntax and formatting of this statement
;; are crucial in writing these statements correctly.
2010-11-04 01:38:20 +00:00
; "Or your fate may be sealed"
(= 'doom (if-not (zero? 1)
2011-10-26 02:55:54 +00:00
'doom
'more-doom))
2011-04-29 20:34:17 +00:00
; "In case of emergency, go fast"
(= :pretty-fast
(explain-exercise-velocity :ten-mph))
2011-04-29 20:34:17 +00:00
; "But admit it when you don't know what to do"
(= :not-so-fast
(explain-exercise-velocity :watching-tv))