Recur不会在完美的尾递归函数中编译

时间:2012-05-09 19:46:26

标签: recursion clojure lisp

(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))))

我得到java.lang.UnsupportedOperationException: Can only recur from tail position但是这个尾部位置。为什么/给出了什么?

1 个答案:

答案 0 :(得分:1)

这适用于Clojure 1.3和1.4。也许在同一个命名空间中还有其他功能导致问题?

相关问题