(defrecord Tiger [age])
;; 对类型的 switch 就是针对类型谓词的 cond:先放具体的值,
;; 再放范围更宽的类型测试
(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))
;; 当分派确实是按类型进行时,
;; Clojure 更倾向于用多重方法或协议,而不是一串测试