获取错误的args数量传递给Clojure函数

时间:2011-10-27 17:33:05

标签: clojure

更多Clojure怪异。我有这个功能,我正在尝试定义和调用。它有3个参数,但当我用3个参数调用它时,我得到

Wrong number of args (1) passed to: solr-query$correct-doc-in-results-QMARK-$fn
 [Thrown class clojure.lang.ArityException]

当我用2个参数调用它时,我得到了

Wrong number of args (2) passed to: solr-query$correct-doc-in-results-QMARK-
  [Thrown class clojure.lang.ArityException]

当我用4个参数调用它时,我得到了

Wrong number of args (4) passed to: solr-query$correct-doc-in-results-QMARK-
  [Thrown class clojure.lang.ArityException]

这是函数的定义:

(defn correct-doc-in-results? [query results docid]
  "Check if the docid we expected is returned in the results"
  (some #(.equals docid) (map :id (get results query))))

以下是我试图调用它的方式(使用emacs中的swank来自REPL):

(correct-doc-in-results? "FLASHLIGHT" all-queries "60184")

任何人都知道发生了什么事吗?为什么我认为我在传递3时只传递1个参数,但在2或4时正确?我不是一个非常流利的clojure程序员,但定义一个函数是非常基本的。

1 个答案:

答案 0 :(得分:15)

注意

之间的区别

solr-query$correct-doc-in-results-QMARK-

solr-query$correct-doc-in-results-QMARK-$fn

第一个引用你的函数correct-doc-in-results?。后者指的是在该函数内定义的一些匿名函数。

如果你传递2或4个参数,你的顶层函数会出现错误,正如预期的那样。当你传递3个参数时,你会收到#(.equals docid)的错误,因为#(.equals docid)想要零参数但是得到一个。尝试将其更改为#(.equals % docid)

相关问题