我能理解这个是如何工作的:
(defmulti area :Shape)
(defmethod area :B [x] (println "Rect"))
(defmethod area :C [x] (println "Circle"))
(defmethod area :default [x] (do (println "Unknown") (:Shape x)))
(area {:Shape :B})
=> Rect
nil
(area {:Shape :Bb})
=> Unknown
:Bb
但是仅仅将:Shape
更改为:Shap
,我就不明白这是如何被调度的:
(defmulti area :Shap)
(defmethod area :B [x] (println "Rect"))
(defmethod area :C [x] (println "Circle"))
(defmethod area :default [x] (do (println "Unknown") (:Shap x)))
(area {:Shap :B})
=> Unknown
:B
(area {:Shap :C})
=> Unknown
:C
在Eclipse中使用Counterclockwise插件的Clojure 1.5.1。
::B
关键字要么不应该有命名空间,要么调用示例中的:B
应该有。 - omiel