7. Conditionals - Koans Walkthrough

This video covers conditionals, such as: if, case and cond.

Here is the 07_conditionals.clj source code:

(defn explain-defcon-level [exercise-term]
  (case exercise-term
        :fade-out          :you-and-what-army
        :double-take       :call-me-when-its-important
        :round-house       :o-rly
        :fast-pace         :thats-pretty-bad
        :cocked-pistol     :sirens

  "You will face many decisions"
  (= :a (if (false? (= 4 5))

  "Some of them leave you no alternative"
  (= [] (if (> 4 3)

  "And in such a situation you may have nothing"
  (= nil (if (nil? 0)
          [:a :b :c]))

  "In others your alternative may be interesting"
  (= :glory (if (not (empty? ()))

  "You may have a multitude of possible paths"
  (let [x 5]
    (= :your-road (cond (= x 6) :road-not-taken
                        (= x 7) :another-road-not-taken
                        :else :your-road)))

  "Or your fate may be sealed"
  (= 'doom (if-not (zero? 0)

  "In case of emergency, sound the alarms"
  (= :sirens
     (explain-defcon-level :cocked-pistol))

  "But admit it when you don't know what to do"
  (= :say-what?
     (explain-defcon-level :yo-mama)))

Clojure Koans Walkthrough in Light Table IDE

This screencast tutorial helps you learn the Clojure programming language. Experience the joy of Clojure in the Light Table IDE as we tour through the Clojure Koans, taking you all the way from Beginner to Intermediate to Advanced.

Clojure is a Lisp created by Rich Hickey that runs on the JVM, as an alternative to Java. ClojureScript can target the web browser environment, and node.js, by compiling down to JavaScript, using the Google Closure compiler. Clojure features immutability, functional programming, and being a Lisp, macros.