Here is the implementation of the Clojure's complement
function:
(defn complement
"Takes a fn f and returns a fn that takes the same arguments as f,
has the same effects, if any, and returns the opposite truth value."
{:added "1.0"
:static true}
[f]
(fn
([] (not (f)))
([x] (not (f x)))
([x y] (not (f x y)))
([x y & zs] (not (apply f x y zs)))))
Why is it defined as a multi-arity function? The following implementation, it seems to me, would achieve the same result:
(defn alternative-complement [f]
(fn [& args] (not (apply f args))))
For what reason, does the Clojure's complement
treat none, single and two arguments as "special cases"?