When and how should independent hierarchies be used in clojure?
Posted
by Rob Lachlan
on Stack Overflow
See other posts from Stack Overflow
or by Rob Lachlan
Published on 2010-06-10T06:20:35Z
Indexed on
2010/06/16
5:32 UTC
Read the original article
Hit count: 418
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.
© Stack Overflow or respective owner