intellij-ideaclojureleiningencursive

Wrong number of args (0) passed... Error?


I believe this is valid Clojure code - and runs fine in a Lein console REPL - but errors inside the Cursive REPL:

Connecting to local nREPL server...
Clojure 1.8.0
nREPL server started on port 41303 on host 127.0.0.1 - nrepl://127.0.0.1:41303
*ns*
=> #object[clojure.lang.Namespace 0x4394b860 "user"]
(defn concat-some
  [f vec1 vec2]
  ((fn [x] (filter f x)
    (concat vec1 vec2))))
=> #'user/concat-some
(concat-some even? [1 2 3] [4 5 6])
clojure.lang.ArityException: Wrong number of args (0) passed to: user/concat-some/fn--4953

Am I missing something here?

Thank you for your help!

Edit and Follow-up:

This is definitely a Parinfer issue. This code:

(defn concat-some
  [f vec1 vec2]
  ((fn [x] (filter f x))
    (concat vec1 vec2)))
(concat-some even? [1 2 3] [4 5 6])

when pasted into the Cursive REPL with Parinfer turned on produces an incorrect paste and the resulting ArityException above. The same code pasted into the same REPL with Paredit turned on or Structural Editing turned off produces the expected output:

;; => #'user/concat-some
;; => (2 4 6)

I did not know that Structural Editing when active in Cursive is used in the editor - AND the REPL. I would still hope that valid code is valid code regardless of mode and wonder if this is the intended result of pasting into a Cursive/Parinfer REPL.(?)

Thank you again for your help with this.


Solution

  • Your editor might have a slurp/barf command that you accidentally triggered with a keyboard shortcut, but this copy/paste has gone awry.

    You have (( which is generally a bad sign unless done correctly like in the examples:

    (defn concat-some
      [f vec1 vec2]
      ((fn [x] (filter f x))
       (concat vec1 vec2)))
    (concat-some even? [1 2 3] [4 5 6])
    

    In yours the last paren on the line with filter is missing, and put at the end of the function instead. this means you are calling a function with 0 arguments, but your call to fn produces a function that takes 1 argument x