A bit ugly, but it works:
(require '[clojure.contrib.java-utils :as cj])
(defn struct-instance? [struct-def sm]
(= (cj/wall-hack-field clojure.lang.PersistentStructMap "def" sm)
struct-def))
(struct-instance? person p)
; => true
(struct-instance? person (conj p [:foo 1] [:bar 2]))
; => true
(defstruct foo :k1 :k2)
(struct-instance? foo p)
; => false
Stuff from clojure.contrib.java-utils
will be available in 1.2 in part in clojure.java
, in part in clojure.contrib.java
(I guess?), and also in clojure.contrib.java-utils
for backward compatibility... Although the details might still change. At any rate, Meikel is right about defrecord
replacing defstruct
, so if you're working on 1.2, prefer that.