title: clojure: use a binding in cond to place recur in tail position only?
body: <p>I have some code that's currently giving me an error, because recur can only be in the tail position. here's the function:</p>
  
  <pre><code>(defmethod transposer
      Long [scale degree]
      (loop [new-scale scale count degree]
      (cond 
          (zero? count) new-scale 
          (&lt; count 0) (recur (step (reverse new-scale)) (inc count)))
          :else (recur (step new-scale) (dec count))))
  </code></pre>
  
  <p>One way I can think to fix this is conditional binding, if I could say:
  <em>when count is less than zero, set count-operator to "inc", otherwise set to "dec", then recur at the end.</em></p>
  
  <p>Then this would fix my problem. But I'm not sure how to do this in clojure, or if it's even possible, when-let and if-let don't seem to do this. What is the best way to fix my code to only use one recur?</p>
  
  <p>EDIT: A couple of things I learned here:</p>
  
  <p>1) "recur" will recur back to the defn, if there's no loop statement. In the book I read, all the examples of recur use loop/recur, so I thought it was necessary to have a loop. it's not, my loop statement want superfluous.</p>
  
  <p>2) Getting the parentheses wrong gave me a confusing error, it struck me as strange that both cond statements wouldn't be considered to be at the tail, since they are mutually exclusive. I should have paid a bit more attention to my paren completion checker.</p>
  
  <p>3) If I ever do want to do conditional binding, I can use a standard "let" statement and just include the conditional logic there. coming from a java background, I sometimes forget the flexibility clojure allows in this area.</p>