Reputation: 5020
Why doesn't the case
clause match the record type?
(defrecord Rec [])
=> fargish.user.Rec
(def rec (->Rec))
=> #'fargish.user/rec
(case (type rec) Rec :YES)
=> IllegalArgumentException No matching clause: class fargish.user.Rec fargish.user/eval25147 (form-init131856794870899934.clj:1)
In case you're wondering, yes, the case expression and the test-constant are equal:
(= (type rec) Rec)
=> true
Upvotes: 3
Views: 995
Reputation: 6509
Rec
is not a compile-time literal. Quoting from https://clojuredocs.org/clojure.core/case:
All manner of constant expressions are acceptable in case, including numbers, strings, symbols, keywords, and (Clojure) composites thereof.
Alternatives:
(cond
(= (type rec) Rec) :YES)
;;=> :YES
(condp = (type rec)
Rec :YES)
;;=> :YES
Upvotes: 4