clojure – defprotocol“没有单一方法”错误似乎是Leiningen的一个错误

我正在学习Clojure中的协议,我遇到了以下代码的错误:

CompilerException java.lang.IllegalArgumentException:没有单一方法:valores_BANG_接口:gangnam.core.Legi找到函数:valores!协议:Legi,编译:(NO_SOURCE_PATH:1:1)

一切都工作得非常好,直到我试图在协议中添加七种方法(valores!下面).所以我把valores复制成了valores!绝对确定我使用相同的代码,除了!最后,它不起作用.我也尝试将其换成另一个名称(删除).

然后我记得我最近运行了lein install,当我再次运行lein安装时,似乎解决了这个问题.知道为什么会这样吗?

(defprotocol Legi
  (lege [self] [self key])
  (carpe! [self] [self key] [self key val])
  (muta!* [self key val])
  (juga! [from label to])
  (claves [self])
  (valores [self])
  (valores! [self]))

(extend-protocol Legi
  Iterable
  (lege
    ([self]
      (for [elm self]
        (lege elm)))
    ([self key]
      (for [elm self]
        (lege elm key))))
  (carpe!
    ([self]
      (for [elm self]
        (carpe! elm)))
    ([self key]
      (for [elm self]
        (carpe! elm key)))
    ([self key val]
      (for [elm self]
        (carpe! elm key val))))
  (muta!*
    [self key val]
    (doall (for [elm self]
      (muta!* elm key val))))
  (juga! [from label to]
    (for [elm from]
      (juga! elm label to)))
  (claves [self]
    (for [elm self]
      (claves elm)))
  (valores [self]
    (for [elm self]
      (valores elm)))
  (valores! [self]
    (for [elm self]
      (valores elm)))
  Element
  (lege 
    ([self]
      (into {} (for [k (.getPropertyKeys self)]
                 [(keyword k) (lege self k)])))
    ([self key]
      (-> self (.getProperty (name key)))))
  (carpe!
    ([self]
      (for [k (.getPropertyKeys self)]
        (carpe! self k)))
    ([self key]
      (let [prop (lege self key)]
        (res
          (-> self (.removeProperty (name key))))
        prop))
    ([self key val]
      (let [prop (lege self key)]
        (if (= val prop)
          (carpe! self key)))))
  (muta!* [self key val]
    (res
      (let [key (name key)]
        (.setProperty self key val)
        self)))
  (juga! [from label to]
    (when (and from to)
      (res
        (.addEdge *g*
          nil from to (name label)))))
  (claves [self]
    (-> self .getPropertyKeys))
  (valores [self]
    (-> self lege vals))
  (valores! [self]
    (-> self lege vals)))

最佳答案 莱因清洁应该为你解决这个问题.

点赞