clojurearity

Arity Overloading in Clojure


Why is the following function not working in Clojure:

(defn tests
  [] 0
  [a b] 1)

It gives the following error: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: a in this context


Solution

  • Each needs to be surrounded by parentheses

    (defn tests 
      ([] 0) 
      ([a b] 1))