<< Back to previous view

[CLJ-1145] thread-last can't accept 0 or 1 forms, thread-first can't accept 0 forms Created: 12/Jan/13  Updated: 13/Jan/13  Resolved: 13/Jan/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Víctor M. Valenzuela Assignee: Unassigned
Resolution: Duplicate Votes: 0
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?).



 Comments   
Comment by Andy Fingerhut [ 12/Jan/13 3:29 PM ]

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?

Comment by Víctor M. Valenzuela [ 12/Jan/13 6:46 PM ]

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.

Comment by Andy Fingerhut [ 13/Jan/13 9:25 AM ]

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

Comment by Andy Fingerhut [ 13/Jan/13 9:40 AM ]

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.

Generated at Fri Oct 24 03:00:32 CDT 2014 using JIRA 4.4#649-r158309.