I have a code that currently gives me an error, because recur can only be in the tail position. here is the function:
(defmethod transposer
Long [scale degree]
(loop [new-scale scale count degree]
(cond
(zero? count) new-scale
(< count 0) (recur (step (reverse new-scale)) (inc count)))
:else (recur (step new-scale) (dec count))))
One way I can think of is to fix this conditional obligation if I could say: when count is less than zero, set the count-operator to "inc", otherwise set to "dec", and then go back to the end.
Then it will fix my problem. But I'm not sure how to do this in clojure, or if possible, when-let and if-let don't seem to do this. What is the best way to fix my code to use only one recur?
EDIT: A few things I learned here:
1) "recur" defn, . , , recur use loop/recur, , . , .
2) , , cond , . .
3) - , "let" . java, clojure .