Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
交换协议中没有单一方法错误!请来Clojure_Clojure - Fatal编程技术网

交换协议中没有单一方法错误!请来Clojure

交换协议中没有单一方法错误!请来Clojure,clojure,Clojure,导致错误: 线程“main”java.lang.IllegalArgumentException中的异常:没有单一方法:接口损坏:协议\记录\u learning.core.Hit\为函数找到的点数:协议损坏:命中点数(core.clj:34) 有人能解释一下这个错误,是什么导致的,以及如何正确地改变原子吗?这应该行得通 (ns protocols-records-learning.core) (defprotocol Hit-points "Able to be harmed by en

导致错误:

线程“main”java.lang.IllegalArgumentException中的异常:没有单一方法:接口损坏:协议\记录\u learning.core.Hit\为函数找到的点数:协议损坏:命中点数(core.clj:34)

有人能解释一下这个错误,是什么导致的,以及如何正确地改变原子吗?

这应该行得通

(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)))
注意,拆下的一对左右翼子板损坏。错误消息是一个笨拙的尝试,告诉您Clojure没有找到算术为1的损坏版本。损害的当事人试图做到这一点:用一个参数(2)调用损害

改进错误消息是一项正在进行的任务,目前尚未达成协议

(defn hurt-ryan
  "Damage Ryan by two points."
  [ryan]
  (swap! ryan damage 2))