clojure - Wrong number of arguments for a simple function -
can explain behavior in clojure code below? don't it. clojure somehow replace or "optimize" function arguments? why calling function single nil argument result in arityexception
?
(defn foo [bar] (reduce #(%1) bar)) (foo nil) -> arityexception wrong number of args (0) passed to: test$foo$fn clojure.lang.afn.throwarity (afn.java:437)
see (doc reduce)
:
[...] if coll contains no items, f must accept no arguments well, , reduce returns result of calling f no arguments. [...]
here coll nil
, being treated collection containing no items (as in similar contexts), , f
#(%1)
.
thus #(%1)
being called no arguments , ends throwing exception see.
Comments
Post a Comment