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:4967 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 [parentMap (:parents h)
	  childsParents (if (parentMap tag)
			  (disj (parentMap tag) parent) #{})
	  newParents (if (not-empty childsParents)
		       (assoc parentMap tag childsParents)
		       (dissoc parentMap tag))
	  deriv-seq (flatten (map #(cons (key %) (interpose (key %) (val %)))
				       (seq newParents)))]
      (if (contains? (parentMap tag) parent)
	(reduce1 #(apply derive %1 %2) (make-hierarchy)
		(partition 2 deriv-seq))
	h))))
Vars in clojure.core/underive:
Used in 0 other vars

Comments top

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