1.3.0 permalink Arrow_down_16x16

ancestors

clojure.core

  • (ancestors tag)
  • (ancestors h tag)
Returns the immediate and indirect parents of tag, 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

  • ;; make up a hierarchy a beagle is a sporting breed is a dog is a quadraped is an 
    ;; animal
    
    user=> (derive ::quadruped ::animal)
    nil
    user=> (derive ::dog ::quadruped)
    nil
    user=> (derive ::sporting_breed ::dog)
    nil
    user=> (derive ::beagle ::sporting_breed)
    nil
    user=> (ancestors ::beagle)
    #{:user/dog :user/sporting_breed :user/animal :user/quadruped}
    user=>
  • ;; use ancestors to show which classes ArrayList derives from and which
    ;; interfaces it implements
    
    user=> (ancestors java.util.ArrayList)
    #{java.util.Collection java.util.AbstractList java.io.Serializable java.lang.Cloneable java.util.List java.lang.Object java.util.AbstractCollection java.util.RandomAccess java.lang.Iterable}
    user=>
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:4901 top

(defn ancestors
  "Returns the immediate and indirect parents of tag, 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"}
  ([tag] (ancestors global-hierarchy tag))
  ([h tag] (not-empty
            (let [ta (get (:ancestors h) tag)]
              (if (class? tag)
                (let [superclasses (set (supers tag))]
                  (reduce1 into1 superclasses
                    (cons ta
                          (map #(get (:ancestors h) %) superclasses))))
                ta)))))
Vars in clojure.core/ancestors:
Used in 0 other vars

Comments top

No comments for ancestors. Log in to add a comment.