4
に呼び出す
(ns protocols-records-learning.core)
(defprotocol Hit-points
"Able to be harmed by environment interaction."
(hit? [creature hit-roll] "Checks to see if hit.")
(damage [creature damage-roll] "Damages target by damage-roll, negated by per-implementation factors.")
(heal [creature heal-roll] "Heals creature by specified amount."))
(defrecord Human [ac, health, max-health]
Hit-points
(hit? [creature hit-roll] (>= hit-roll ac))
(damage [creature damage-roll] (if (pos? damage-roll) (Human. ac (- health damage-roll) max-health)))
(heal [creature heal-roll] (if (pos? heal-roll)
(if (>= max-health (+ heal-roll health))
(Human. ac max-health max-health)
(Human. ac (+ heal-roll health) max-health)))))
(def ryan (atom (Human. 10 4 4)))
(defn hurt-ryan
"Damage Ryan by two points."
[ryan]
(swap! ryan (damage 2)))
がエラーにつながる:単一の方法:インターフェースの損傷:機能見つかりprotocols_records_learning.core.Hit_points:プロトコルの損傷:ヒットスレッド「メイン」java.lang.IllegalArgumentExceptionがでスワップでプロトコルエラーが発生しました。 Clojureの
例外-points(core.clj:34)
誰かがこのエラーを説明し、それを引き起こしていること、そして原子を正しく変更する方法はありますか?