Clojure

thread-last can't accept 0 or 1 forms, thread-first can't accept 0 forms

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

At times, as the artifact of repl experimentation or a refactoring in progress, one wants to eval a threaded form with 1 or (less likely) 0 arguments.

(-> 42) ; fine
(->> 42) ; throws "ArityException Wrong number of args (1) passed to: core$-GT".

(->) ; throws "ArityException Wrong number of args (0) passed to: core$" (sic)
(->>) ; throws "ArityException Wrong number of args (0) passed to: core$-GT".

Apologies for the text rendering (how to cite code?).

Activity

Hide
Andy Fingerhut added a comment -

Is this a duplicate with CLJ-1086, CLJ-1121, or the combination of those two?

If arity 0 is a new aspect of this ticket, what would you expect the arity 0 versions to be transformed into? nil?

Show
Andy Fingerhut added a comment - Is this a duplicate with CLJ-1086, CLJ-1121, or the combination of those two? If arity 0 is a new aspect of this ticket, what would you expect the arity 0 versions to be transformed into? nil?
Hide
Víctor M. Valenzuela added a comment -

Surely a duplicate - but Jira's search couldn't find those! (used "->", "thread-last" etc as search queries).

While fairly unlikely to use / noisy to implement, the thing about feeding 0-arities to the threading macros is that they throw in exchange an unrelated exception rather than e.g. "ArityException Wrong number of args (0) passed to: core$->".

Don't know if this is simply how macros (can) work, but it called my attention.

Feel free to close my issue.

Show
Víctor M. Valenzuela added a comment - Surely a duplicate - but Jira's search couldn't find those! (used "->", "thread-last" etc as search queries). While fairly unlikely to use / noisy to implement, the thing about feeding 0-arities to the threading macros is that they throw in exchange an unrelated exception rather than e.g. "ArityException Wrong number of args (0) passed to: core$->". Don't know if this is simply how macros (can) work, but it called my attention. Feel free to close my issue.
Hide
Andy Fingerhut added a comment -

I will go ahead and close this case as a duplicate. FYI, below is the behavior if the CLJ-1121 patch CLJ-1121-v002.patch and the CLJ-1083 patch CLJ-1083-attachments/better-throw-arity-messages.diff are both applied (the second one improves the error message in the 0-arity case):

Clojure 1.5.0-master-SNAPSHOT
user=> (->)
ArityException Wrong number of args (0) passed to: core/-> clojure.lang.Compiler.macroexpand1 (Compiler.java:6472)
user=> (-> 5)
5
user=> (->>)
ArityException Wrong number of args (0) passed to: core/->> clojure.lang.Compiler.macroexpand1 (Compiler.java:6472)
user=> (->> 5)
5

Show
Andy Fingerhut added a comment - I will go ahead and close this case as a duplicate. FYI, below is the behavior if the CLJ-1121 patch CLJ-1121-v002.patch and the CLJ-1083 patch CLJ-1083-attachments/better-throw-arity-messages.diff are both applied (the second one improves the error message in the 0-arity case): Clojure 1.5.0-master-SNAPSHOT user=> (->) ArityException Wrong number of args (0) passed to: core/-> clojure.lang.Compiler.macroexpand1 (Compiler.java:6472) user=> (-> 5) 5 user=> (->>) ArityException Wrong number of args (0) passed to: core/->> clojure.lang.Compiler.macroexpand1 (Compiler.java:6472) user=> (->> 5) 5
Hide
Andy Fingerhut added a comment -

The issue of a poor error message with 0-arity threading macros is improved by the patch attached to ticket CLJ-1083, and adding handling of the 1-arity case is improved by the patch attached to ticket CLJ-1121.

Show
Andy Fingerhut added a comment - The issue of a poor error message with 0-arity threading macros is improved by the patch attached to ticket CLJ-1083, and adding handling of the 1-arity case is improved by the patch attached to ticket CLJ-1121.
Andy Fingerhut made changes -
Field Original Value New Value
Resolution Duplicate [ 3 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: