(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)))
Führt zu Fehlern:
Ausnahme im Thread "main" java.lang.IllegalArgumentException: Keine einzelne Methode: damage of interface: protocols_records_learning.core.Hit_points gefunden für Funktion: damage of protocol: Hit-points (core.clj:34)
Kann jemand diesen Fehler erklären, und was ihn verursacht, und wie man das Atom richtig ändert?