O'Reilly logo

Clojure for Domain-specific Languages by Kelker Ryan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Relationships with hierarchies

Hierarchies in Clojure are used to make child-parent relationships between classes, keywords, and symbols. These relationships can be used to determine which code body to evaluate for a defmulti function. This chapter will go over the capabilities of hierarchies, and then introduce examples of how to use hierarchies with defmulti polymorphism.

Hierarchies are global by default but, for the following example, the local-h symbol will hold the relationships. Because the make-hierarchy form returns a persistent array-map, the hierarchy is wrapped inside an atom so that the swap! form can apply and maintain changes to the hierarchy:

user> (def local-h (atom (make-hierarchy)))
#'user/local-h

In the following example, the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required