user=> (defmulti thing)
#'user/thing
user=> (defmethod thing :default [x] :hi)
#object[clojure.lang.MultiFn 0x7b60c3e "clojure.lang.MultiFn@7b60c3e"]
user=> (thing :hello)
Execution error (NullPointerException) at user/eval144 (REPL:1).
null
user=>
有人对这个行为感到惊讶,并忽略了没有定义分发函数的错误。值得指出的是,对 defmulti
进行了一些验证
(defmulti thing [x] (fn [x] x))
Syntax error macroexpanding defmulti at (REPL:1:1).
The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)
user=>