Clojure's system for creating an ad hoc hierarchy of keywords is familiar to most people who have spent a bit of time with the language. For example, most demos and presentations of the language include examples such as
(derive ::child ::parent)
and they go on to show how this can be used for multi-method dispatch.
In all of the slides and presentations that I've seen, they use the global hierarchy. But it is possible to put keyword relationships in independent hierarchies, by using (derive h ::child ::parent), where h is created by (make-hierarchy). Some questions, therefore:
- Are there any guidelines on when this is useful or necessary?
- Are there any functions for manipulating hierarchies?
Merging is particularly useful, so I do this:
(defn merge-h [& hierarchies]
(apply merge-with (cons #(merge-with clojure.set/union %1 %2) hierarchies))
But I was wondering if such functions already exist somewhere.
EDIT: Changed "custom" hierarchy to "independent" hierarchy, since that term better describes this animal. Also, I've done some research and included my own answer below. Further comments are welcome.