user797257
user797257

Reputation:

Recur won't compile in perfectly tail-recursive function

(defn matrix-diagonals-odd-p
  ([matrix] (matrix-diagonals-odd-p matrix 0))
  ([matrix offset]
     (let [len (alength matrix)]
       (if (> (+ (bit-shift-right len 1) (bit-and len 1)) offset)
         (if (= (+ (bit-and (get (get matrix offset) offset) 1)
                   (bit-and (get (get matrix (- len 1 offset)) (- len 1 offset)) 1)
                   (bit-and (get (get matrix offset) (- len 1 offset)) 1)
                   (bit-and (get (get matrix (- len 1 offset)) offset) 1)) 4)
         (recur matrix (inc offset))
         false) true))))

And I'm getting java.lang.UnsupportedOperationException: Can only recur from tail position But this is tail position. Why / what gives?

Upvotes: 2

Views: 150

Answers (1)

Eli Schneider
Eli Schneider

Reputation: 4955

This is works for me with Clojure 1.3 and 1.4. Maybe there is other functions in the same namespace that causing trouble?

Upvotes: 1

Related Questions