我为帕斯卡三角形编写了以下函数。为什么打电话
pascal_cont(a-1, b-1, (x:Int) => pascal_cont(a, b-1, (y:Int) => cont(x + y)))
不是尾递归吗?
def pascal(c: Int, r: Int): Int = {
def pascal_cont(a:Int, b:Int, cont: (Int) => Int): Int = {
if (a==0 || a==b) cont(1)
else pascal_cont(a-1, b-1, (x:Int) => pascal_cont(a, b-1, (y:Int) => cont(x + y)))
}
pascal_cont(c,r,n => n)
}