2
votes

I am a bit confused about whether I can only use clojure multimethods on clojure structures represented by Java classes, or can I base multimethods to dispatch on structs or other properties?

3

3 Answers

4
votes

It is very common to build multimethods that dispatch on the class of the first or only argument. In this case the "class" may be a Java class, a record (defrecord generates a Java class), or even an internal Clojure type like ISeq.

You can also dispatch on an arbitrary function of the args passed to the function. For example, you could compute a function and dispatch on a keyword if you wanted.

3
votes

You can dispatch multimethods on an arbitrary function of the arguments (that function gets passed in as the second argument to defmulti. http://clojure.org/multimethods provides more details.

2
votes

You can make your multimethods dispatch on any function you choose.