When and how should custom 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/10 6:22 UTC
Read the original article Hit count: 364

Filed under:
|
|

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 keyword relationships in custom hierarchies. 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.

© Stack Overflow or respective owner

Related posts about clojure

Related posts about hierarchy