On 19.03.2010, at 12:09, Per Vognsen wrote:

> It looks like there isn't a way to get at the class behind a deftyped
> type other than constructing a dummy instance and taking its class,
> because the generated class has a gensymmed name. I was doing
> something where I needed to test when something was an instance of a
> deftype, so I added this to the `(do ...) block in deftype's
> implementation:

The official approach is to check for type rather than class, the type being 
the namespace-qualified keyword version of the type name. The class is 
considered an implementation detail. Considering that there is already an 
alternative implementation of Clojure (ClojureCLR) and that there might be more 
in the future, this is pretty reasonable in my opinion.

Here's an (untested) example:

(deftype Foo [bar])

(defn is-this-a-foo? [x]
  (identical? (type x) ::Foo))

Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to