Clojure `defn` parameter in parentheses or not
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).
链接地址: http://www.djcxy.com/p/82572.html