Details
-
Type:
Defect
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: Release 1.5
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
(-> [1 2 3] (fn [args] apply + args))
CompilerException java.lang.Exception: Unsupported binding form: 1, compiling:(NO_SOURCE_PATH:1:13)
The expression is expanded to:
(fn [1 2 3] [args] apply + args)
If this is intended behaviour then at the least the compiler error message is confusing. It would be preferable if the -> macro checked for (fn..) before treating a form as a sequence and injecting the argument.
Note that this works as you might have hoped:
(-> [1 2 3] ((fn [args] (apply + args))))
because it expands into:
((fn [args] (apply + args)) [1 2 3])
Your suggestion that -> check for (fn ...) before treating it as a sequence and injecting the argument leaves open the question: Why only (fn ...) should be treated specially? Why not (let ...), (for ...), (doseq ...), etc? And if you go that far, how do you decide what should be allowed and what not?