当我用以下代码呈现它时(第一行的功能被注释掉了,因为它对于确保正确性是必要的,但我想确保这不是导致问题的原因),Kotlin编译器告诉我递归调用不是尾巴呼叫。
class Env(val global: Map<Symbol, Term>, val outer: Env?, val local: Array<Term?>) {
tailrec operator fun get(i: Int): Term {
// if (i < local.size) return local[i]!!
val o = outer!!
return o[i - local.size]
}
}
If I change the syntax of the last line to explicitly say o.get(i - local.size)
instead of using operator overloading, it makes no difference. Ditto if I uncomment the first line.
我一辈子都看不到如何失败。也许我一直盯着它看了这么久,但我却忽略了它。谁能看到我在做什么错?