(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)))
Приводит к ошибке:
Исключение в потоке "main" java.lang.IllegalArgumentException: Нет единственного метода: повреждение интерфейса: protocol_records_learning.core.Hit_points найдено для функции: повреждение протокола: Hit-points (core.clj: 34)
Может кто-нибудь объяснить эту ошибку, и чем она вызвана, и как правильно изменить атом?