【问题标题】:Recur won't compile in perfectly tail-recursive functionRecur 不会以完美的尾递归函数编译
【发布时间】:2012-05-09 19:46:26
【问题描述】:
(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 但这个的尾部位置。为什么/什么给了?

【问题讨论】:

  • 这看起来不错。你能仔细检查一下这实际上是你正在测试的吗?错误实际上可能很长吗?
  • 好的,开发 Clojure 的最佳方式是交互式地使用 REPL,而不是编译和运行 Java。我怀疑您只是不小心运行了旧版本。

标签: recursion clojure lisp


【解决方案1】:

这适用于 Clojure 1.3 和 1.4。也许同一个命名空间中还有其他功能会造成麻烦?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多