Clojure Multimethod错误:调度值的多方法中没有方法:Null

时间:2016-11-29 20:17:06

标签: clojure multimethod

"were-creatures" example from the book Clojure for the Brave and True中有以下代码:

(defmulti full-moon-behavior (fn [were-creature] (:were-type were-creature)))

(defmethod full-moon-behavior :wolf
  [were-creature]
  (str (:name were-creature) " will howl and murder"))

(defmethod full-moon-behavior :simmons
  [were-creature]
  (str (:name were-creature) " will encourage people and sweat to the oldies"))

当我尝试在REPL中运行两个示例中的任何一个时:

(full-moon-behavior {:were-type :wolf
                     :name "Rachel from next door"})

(full-moon-behavior {:name "Andy the baker"
                     :were-type :simmons})

我收到以下错误消息:

IllegalArgumentException No method in multimethod 'full-moon-behavior' 
for dispatch value: null  clojure.lang.MultiFn.getFn (MultiFn.java:156)

如何修复我的代码,以便输出以下内容?

; => "Rachel from next door will howl and murder"
; => "Andy the baker will encourage people and sweat to the oldies"

0 个答案:

没有答案