Welcome! Please see the About page for a little more info on how this works.

0 votes
in Macros by
retagged by

I discovered a minor edge case with the defmulti macro when attempting to use a literal map as the dispatch-fn:
(defmulti frob {:dispatch :map})
According to its arglist, the attr-map? argument is optional, so the map should be parsed as its compulsory dispatch-fn. Instead it is taken to be the var metadata map, and the function is set to nil.
(frob :dispatch) ;; => Execution error (NullPointerException) at scratch/eval68113 (REPL:169). ;; Cannot invoke "clojure.lang.IFn.invoke(Object)" because "this.dispatchFn" is null
Obviously using maps to dispatch a multimethod is not very sensible (amounting to a closed translation map from arg->dispatch value), but it might be a case to consider.

1 Answer

0 votes