Begin Edit:
Mea Culpa! I apologize.
I was running this in the cake repl at Clojure 1.2.1, and it honestly did not work. Now it does after exiting cake repl and a
The problem could perhaps be related to the undocumented defonce
-like behavior of defmulti
.
If you reload a namespace that contains a (defmulti foo ...)
form then that defmulti
won't be updated. This often means that the dispatch function will not be updated but all method implementations (in the same namespace) will. (defmulti foo ...)
does nothing if the foo
var is already bound to a value.
To fix this in a REPL, remove the multimethod var (ns-unmap 'the.ns 'the-multimethod)
and then reload the namespace (require 'the.ns :reload)
.
To prevent this problem you can define the dispatch function separately and pass its var to defmulti
like this:
(defn foo-dispatch [...]
...)
(defmulti foo #'foo-dispatch)
When the code looks like this it's enough to reload the namespace if you make a change to foo-dispatch
.