控制流 / 条件语句 / switch/case 语句

(defrecord Tiger [age])

;; a switch over types is a cond over type predicates: values come first,
;; the wider type tests after them
(defn describe [x]
  (cond
    (= x 2"two"
    (instance? Tiger x) "Tiger!!!"
    (= x "Error""Error string"
    (int? x) "Int type"
    (string? x) (str "string value '" x "'")
    :else "Unknown type"))

(println (describe (->Tiger 15)))
;; printed: Tiger!!!
(println (describe "test"))
(println (describe 5))
(println (describe 2))
(println (describe 3.14))

;; when the dispatch is really about types, Clojure prefers a multimethod
;; or a protocol to a chain of tests