You're viewing version 1.2.0 of ancestors. The latest stable version of Clojure Core is 1.3.0.
1.2.0 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:4434 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))]
                  (reduce into superclasses
                    (cons ta
                          (map #(get (:ancestors h) %) superclasses))))
                ta)))))
Vars in clojure.core/ancestors: class? cons defn get into let map not-empty reduce
Used in 1 other vars ancestors

Comments top

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