Practical PolymorphismIn an object-oriented language like Java, there are a large amount of types for every situation. Clojure takes another approach. It has a small amount of types and many different functions for them. However, being pragmatic, Clojure realizes that polymorphism is flexible and useful for some situations. Let’s take a look at a few ways that Clojure can flex its polymorphic muscles.
If we wanted to have a function that would behave differently based on the kind of input we had, we could use a case like statement. This example uses a function called cond that behaves differently depending on whether the argument is a keyword, string, or number, and returns the caterpillar’s questions to Alice:

The class input is compared, and if it is a string it will return "String - Who are you?"

If it is a keyword, it will return "Keyword - Who are you?"

If it is a number (class of Long), it will return "Number - who are you?"

When called with a keyword, returns the clause that matched the keyword class.

When called with a string, returns the clause that matched the string class.

When called with a number, returns the clause that matched the number class.

When called with a boolean, returns nil because there is no matching cond clause.