I saw a Clojure function is defined as
(defn toInt([i] (Integer. i)))
why the parameter [i]
is included in parentheses? is this the same as below? any differences?
(defn toInt [i] (Integer. i))
The first uses the notation for arity overloading, but contains only one arity.
Example with two arities:
(defn my-add
([x] (+ x 1))
([x y] (+ x y)))
(my-add 1) ;;=> 2
(my-add 1 2) ;;=> 3
Also see http://clojure.org/functional_programming (search for arity overloading).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With