当使用 defrecord 声明 MyRecordType 时,我无法弄清楚如何执行类似 (instance?MyRecordType x) 之类的操作。记录的类型和类始终是 clojure.lang.PersistentArrayMap。
例如:
(defrecord MyRecord1 [data-field1 data-field2])
(defrecord MyRecord2 [data-field1])
(def x (->MyRecord1 1 2))
(def y (->MyRecord2 3))
(instance? MyRecord1 x)
=> false
(instance? MyRecord2 y)
=> false
(type x)
=> clojure.lang.IPersistentMap
(class y)
=> clojure.lang.IPersistentMap
(= (type x) (type y))
=> true