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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With