ClojureDocs

Nav

Namespaces

ancestors

clojure.core

Available since 1.0 (source)
  • (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
3 Examples
;; 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=>
;; use ancestors in defrecords to show which defprotocols implements
user=> (defprotocol Fly
           (fly [this]))

user=> (defrecord Bird [name] Fly
           (fly [this] (str (:name this) " flies....")))

user=> (ancestors Bird)
;; #{clojure.lang.IPersistentCollection 
;;   user.Fly 
;;   clojure.lang.IHashEq clojure.lang.ILookup 
;;   java.util.Map java.lang.Iterable 
;;   java.io.Serializable 
;;   java.lang.Object 
;;   clojure.lang.IMeta 
;;   clojure.lang.Seqable 
;;   clojure.lang.IRecord 
;;   clojure.lang.IObj 
;;   clojure.lang.Associative 
;;   clojure.lang.Counted 
;;   clojure.lang.IKeywordLookup 
;;   clojure.lang.IPersistentMap}
See Also

Returns the immediate parents of tag, either via a Java type inheritance relationship or a relatio...

Added by klauern

Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualifi...

Added by klauern

Removes a parent/child relationship between parent and tag. h must be a hierarchy obtained from ma...

Added by klauern

Returns the immediate and indirect children of tag, through a relationship established via derive....

Added by klauern

Creates a hierarchy object for use with derive, isa? etc.

Added by klauern

Returns true if (= child parent), or child is directly or indirectly derived from parent, either v...

Added by klauern

Returns the immediate and indirect superclasses and interfaces of c, if any

Added by alilee
0 Notes
No notes for ancestors