concept ad hoc polymorphism in category clojure

appears as: d hoc polymorphism, Ad hoc polymorphism
Clojure in Action, Second Edition

This is an excerpt from Manning's book Clojure in Action, Second Edition.

Notice that this example of ad hoc polymorphism doesn’t allow calling code to “train” the ad-hoc-type-namer function to understand new types—you can’t add new clauses to the condp expression without rewriting the function. This property is called closed dispatch because the list of available implementations (that is, to which you can dispatch) can’t be changed from the outside. But you can implement open dispatch by keeping the implementations outside your type-naming function:

Ad hoc polymorphism is simple and easy to understand, but it’s done from the perspective of the implementations that use a type, not from the perspective of the types being used. The next form of polymorphism is more from the type’s perspective.

We’ve covered the basics of multimethods for ad hoc polymorphism using a single dispatch value to select a matching implementation. Now you’re going to see how multimethods can consider multiple dispatch values to select an implementation.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest