You're viewing version 1.2.0 of isa?. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (isa? child parent)
  • (isa? h child parent)
Returns true if (= child parent), or child is directly or indirectly derived from
parent, either via a Java type inheritance relationship or a
relationship established via derive. h must be a hierarchy obtained
from make-hierarchy, if not supplied defaults to the global
hierarchy

2 Examples top

  • user=> (import 'java.util.PriorityQueue)
    java.util.PriorityQueue
    
    user=> (bases PriorityQueue)
    (java.util.AbstractQueue java.io.Serializable)
    
    user=> (import 'java.util.AbstractQueue)
    java.util.AbstractQueue
    
    user=> (isa? PriorityQueue AbstractQueue)
    true
    
    user=> (bases AbstractQueue)
    (java.util.AbstractCollection java.util.Queue)
    
    user=> (isa? PriorityQueue java.util.AbstractCollection)
    true
    
    user=> (isa? PriorityQueue java.util.Queue)
    true
    
    user=> (isa? java.util.PriorityQueue java.util.TreeMap)
    false
  • user=> (derive ::Feline ::Animal)
    nil
    user=> (derive ::Cat ::Feline)
    nil
    
    user=> (derive ::Lion ::Feline)
    nil
    
    user=> (isa? ::Lion ::Feline)
    true
    
    user=> (isa? ::Lion ::Animal)
    true
    
    user=> (isa? ::Tuna ::Feline)
    false
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4400 top

(defn isa?
  "Returns true if (= child parent), or child is directly or indirectly derived from
  parent, either via a Java type inheritance relationship or a
  relationship established via derive. h must be a hierarchy obtained
  from make-hierarchy, if not supplied defaults to the global
  hierarchy"
  {:added "1.0"}
  ([child parent] (isa? global-hierarchy child parent))
  ([h child parent]
   (or (= child parent)
       (and (class? parent) (class? child)
            (. ^Class parent isAssignableFrom child))
       (contains? ((:ancestors h) child) parent)
       (and (class? child) (some #(contains? ((:ancestors h) %) parent) (supers child)))
       (and (vector? parent) (vector? child)
            (= (count parent) (count child))
            (loop [ret true i 0]
              (if (or (not ret) (= i (count parent)))
                ret
                (recur (isa? h (child i) (parent i)) (inc i))))))))
Vars in clojure.core/isa?: = and class? contains? count defn inc loop not or some supers vector?

Comments top

No comments for isa?. Log in to add a comment.