3 ms·
Many functions and macros in Clojure rely on reducing variadic parameters using recursion, e.g. (defn max "Returns the greatest of the nums." ([x] x)
by vorg 11y ago
Many functions and macros in Clojure rely on reducing variadic parameters using recursion, e.g.
(defn max "Returns the greatest of the nums."
([x] x)
([x y] (. clojure.lang.Numbers (max x y)))
([x y & more] (reduce1 max (max x y) more)))
You'd be limited to 2 params if you didn't have variadicity. Some macros like switching, which in Clojure is called `condp`, would lose their elegant single-parens appearance if variadicity wasn't allowed.
- lisper 11y agoAgain, you are confusing syntax and semantics. All you need to do to have the exact same surface syntax with single-argument functions is to stipulate that the arguments to a macro expander are passed in as a (single) list.