Clojure定义类型和协议

Clojure定义类型和协议,clojure,clojure-protocol,Clojure,Clojure Protocol,我的(ns处理程序)中有此Clojure代码 在我的core.clj中,我得到了以下代码(省略了几行和命名空间内容): 操作处理程序是其中一个deftype处理程序的有效实例。 当我尝试编译时,出现以下错误: java.lang.IllegalArgumentException: No single method: handle of interface: handlers.ActionHandler found for function: handle of protocol: ActionH

我的(ns处理程序)中有此Clojure代码

在我的core.clj中,我得到了以下代码(省略了几行和命名空间内容):

操作处理程序是其中一个deftype处理程序的有效实例。 当我尝试编译时,出现以下错误:

java.lang.IllegalArgumentException: No single method: handle of interface: handlers.ActionHandler found for function: handle of protocol: ActionHandler
我确实读到过当无效数量的参数被传递到协议函数时会产生误导性的错误消息,但是,正如您所看到的,情况并非如此

有什么问题吗?有什么建议吗?
格雷格

我相信你传递的是两个参数,而不是一个。所发生的事情是协议方法的第一个参数是
这个
参数

试试这个

(defprotocol ActionHandler
  (handle [this params session]))

(defrecord Response [status headers body])

(deftype AHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "Yuppi, a-handler works")))


(deftype BHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "YES, the b-handler is ON")))

(deftype CHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "C is GOOD, it's GOOD!")))

谢谢这正是我遇到的问题。
java.lang.IllegalArgumentException: No single method: handle of interface: handlers.ActionHandler found for function: handle of protocol: ActionHandler
(defprotocol ActionHandler
  (handle [this params session]))

(defrecord Response [status headers body])

(deftype AHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "Yuppi, a-handler works")))


(deftype BHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "YES, the b-handler is ON")))

(deftype CHandler []
  ActionHandler
  (handle [this params session]
          (Response. 200 {"Content-Type" "text/plain"} "C is GOOD, it's GOOD!")))