You're viewing version 1.2.0 of underive. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

underive

clojure.core

  • (underive tag parent)
  • (underive h tag parent)
Removes a parent/child relationship between parent and
tag. h must be a hierarchy obtained from make-hierarchy, if not
supplied defaults to, and modifies, the global hierarchy.

1 Example top

  • ;; create a simple hierarchy using the global hierarchy
    ;; and demonstrate how underive is used
    
    user=> (derive ::dog ::animal)
    nil
    user=> (derive ::spaniel ::dog)
    nil
    user=> (derive ::tabby ::dog)
    nil
    user=> (ancestors ::tabby)
    #{:user/dog :user/animal}
    user=> (underive ::tabby ::dog)
    nil
    user=> (ancestors ::tabby)
    nil
    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:4498 top

(defn underive
  "Removes a parent/child relationship between parent and
  tag. h must be a hierarchy obtained from make-hierarchy, if not
  supplied defaults to, and modifies, the global hierarchy."
  {:added "1.0"}
  ([tag parent] (alter-var-root #'global-hierarchy underive tag parent) nil)
  ([h tag parent]
   (let [tp (:parents h)
         td (:descendants h)
         ta (:ancestors h)
         tf (fn [m source sources target targets]
              (reduce
               (fn [ret k]
                 (assoc ret k
                        (reduce disj (get targets k) (cons target (targets target)))))
               m (cons source (sources source))))]
     (if (contains? (tp tag) parent)
       {:parent (assoc (:parents h) tag (disj (get tp tag) parent))
        :ancestors (tf (:ancestors h) tag td parent ta)
        :descendants (tf (:descendants h) parent ta tag td)}
       h))))
Vars in clojure.core/underive: alter-var-root contains? defn let
Used in 0 other vars

Comments top

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