在"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"