On Feb 29, 8:02 am, Paul Drummond
As in Python/CL/Scheme, in Clojure the object has a type, not the
symbol/variable. Clojure doesn't have a type system independent of
Java's, so the normal Java method applies:
(. a (getClass))
There isn't yet a Clojure function that makes this shorter, and
surprisingly no one has asked for one (or has everyone rolled their
own?)
As always in a system with inheritance, it can be dangerous to rely on
the concrete types of things:
user=> (def a {"a" 2})
user=> (. a (getClass))
class clojure.lang.MapEntry
user=> (def ab {"a" 2 "b" 3})
user=> (. ab (getClass))
class clojure.lang.PersistentHashMap
Whereas testing whether something implements a specific interface is
generally more useful:
user=> (map? a)
true
user=> (map? ab)
true
where (map? x) is a helper function defined as (instance?
IPersistentMap x). There are similar helpers for symbol?, vector?,
seq? string? etc.
Rich