Reputation: 48766
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
Upvotes: 2
Views: 2112
Reputation: 1203
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
Upvotes: 0
Reputation: 26446
Each needs to be surrounded by parentheses
(defn tests
([] 0)
([a b] 1))
Upvotes: 9