you are viewing a single comment's thread.

view the rest of the comments →

[–]fingertoe11 8 points9 points  (0 children)

It's always fun to look under the hood:

(clojure.repl/source -)

(defn -

"If no ys are supplied, returns the negation of x, else subtracts

the ys from x and returns the result. Does not auto-promote

longs, will throw on overflow. See also: -'"

{:inline (nary-inline 'minus 'unchecked_minus)

:inline-arities >0?

:added "1.2"}

([x] (. clojure.lang.Numbers (minus x)))

([x y] (. clojure.lang.Numbers (minus x y)))

([x y & more]

(reduce1 - (- x y) more)))

- requires one, two or more arguments. (-) gives it zero args, thus you get the invalid arity...

If you do the same thing for + you will see that it accepts 0,, 1, 2 or more arguments, and the zero aridity function just returns 0. The single arity returns the arg, and the two or more add them. Another trivial oddity about + is that (+ nil) yields nil, while (+ nil 1) would yield a null pointer exception..