Chapter 9Multimethods

Clojure multimethods provide a flexible way to associate a function with a set of inputs. This is similar to Java polymorphism but more general. When you call a Java method, Java selects a specific implementation to execute by examining the type of a single object. When you call a Clojure multimethod, Clojure selects a specific implementation to execute by examining the result of any function you choose, applied to all the function’s arguments.

In this chapter, you’ll develop a thirst for multimethods by first living without them. Then you’ll build an increasingly complex series of multimethod implementations—first using multimethods to simulate polymorphism and then using multimethods to implement various ad hoc taxonomies. ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.