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
;; 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=>
(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)))))
Comments top
No comments for ancestors. Log in to add a comment.