This should be a very trivial question.
i am new to Clojure and writing this if-then-else based on: http://clojure.org/special_forms#Special%20Forms–%28if%20test%20then%20else?%29
However, I keep getting this error:
java.lang.Exception: Too many arguments to if (NO_SOURCE_FILE:424)
// This code has infinite recursion bugs; but it should compile!
(defn sumdown [sum x]
(
if (foo x)
(do
(recur (+ sum x) (dec x))
)
else do(
(recur (+ sum x) (dec x))
)
)
)
In the template:
both
thenandelsedon’t represent keywords, but actual expressions. The?indicates theelseexpression is optional.The test condition is evaluated and based on its value, the appropriate branch expression is evaluated and “returned” as the value of the entire if expression.
For example, this would define an absolute value function: