Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting wrong number of args passed to a Clojure function

Tags:

clojure

More Clojure weirdness. I have this function I'm trying to define and call. It has 3 arguments, but when I call it with 3 arguments I get

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

when I call it with 2 arguments I get

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

and when I call it with 4 arguments I get

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

here is the definition of the function:

(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))))

and here is how I'm trying to call it (from the REPL using swank in emacs):

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

anyone have any idea what's going on? Why does it think I'm only passing in 1 argument when I am passing 3, but gets it right for 2 or 4? I'm not a very fluent clojure programmer yet, but defining a function is pretty basic.

like image 284
Dave Kincaid Avatar asked Oct 27 '11 17:10

Dave Kincaid


1 Answers

Note the difference between

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

and

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

The first refers to your function correct-doc-in-results?. The latter refers to some anonymous function defined inside that function.

If you pass 2 or 4 arguments, you're getting an error for your toplevel function, as expected. When you pass 3 arguments, you're getting an error for #(.equals docid), because #(.equals docid) wants zero arguments but is getting one. Try changing it to #(.equals % docid).

like image 87
Brian Carper Avatar answered Nov 07 '22 19:11

Brian Carper