title: Clojure multimethod on class OR keyword
body: <p>Suppose I have this multimethod</p>
  
  <pre><code>(defmulti m (fn [v] [(:type v)]))
  
  (defmethod m [Object] [k] (prn "Object"))
  
  (defmethod m [:mykwd] [k] (prn "mykwd"))
  </code></pre>
  
  <p>When I call it with subclass of <code>Object</code>, it correctly dispatches to the first implementation:</p>
  
  <pre><code>(m {:type String})
  "Object"
  </code></pre>
  
  <p>With the <code>:mykwd</code> it also works as expected:</p>
  
  <pre><code>(m {:type :mykwd})
  "mykwd"
  </code></pre>
  
  <p>But when I provide another keyword I get an exception:</p>
  
  <pre><code>(m {:type :anotherkwd})
  #&lt;CompilerException java.lang.IllegalArgumentException: No method in multimethod 'm'
  for dispatch value: [:anotherkwd] (NO_SOURCE_FILE:0)&gt;
  </code></pre>
  
  <p>How exactly does this dispatch work?</p>
  
  <p>Is it possible to preserve this behavior for class inheritance and still have a "default" implementation that catches <em>all</em> keywords?</p>
  
  <p><strong>EDIT</strong> This example is simplistic, but I need it to work with binary functions. My real need is below. I don't see how I could apply <code>:default</code> to it.</p>
  
  <pre><code>(defmulti m (fn [arg mp] [(class arg) (:type mp)]))
  </code></pre>
  
  <p>Then I'm looking for a way to define it for the case when <code>arg</code> is <code>nil</code> and <code>(:type mp)</code> is anything. This works when value for <code>:type</code> is a class, but not for <em>any</em> keyword:</p>
  
  <pre><code>(defmethod m [nil Object] [arg mp] (prn "Whatever"))
  </code></pre>