Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the name of a Clojure struct type?

Tags:

struct

clojure

When defining a struct type and instance, I can print the value and get the "struct" implementation type:

(defstruct person :name :age)
(def p (struct person "peter" 30))

user=> p
{:name "peter", :age 30}
user=> (type p)
clojure.lang.PersistentStructMap

But is it possible to tell whether p is an instance of the struct type "person"?

like image 328
j-g-faustus Avatar asked Jun 11 '10 05:06

j-g-faustus


1 Answers

See: this post in the Clojure Google Group. In general the group archives are a treasure chest...

Note: The functionality of structs is replaced by records. Then this is not a problem anymore, because records really define new type and you can check with instance? whether something is of record of a certain type.

like image 189
kotarak Avatar answered Sep 23 '22 03:09

kotarak