2

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

Sibi
  • 47,472
  • 16
  • 95
  • 163

2 Answers2

9

Each needs to be surrounded by parentheses

(defn tests 
  ([] 0) 
  ([a b] 1))
A. Webb
  • 26,227
  • 1
  • 63
  • 95
0

If you want more than 2x var's, use & more:

(defn maxz
  "Returns the greatest of the nums."
  ([x] x)
  ([x y] (if (> x y) x y))
  ([x y & more]
   (reduce maxz (maxz x y) more)))

(maxz 1 2 3 4 5 100 6)

=> 100

a.k
  • 1,035
  • 10
  • 27