Tail recursion on R Statistical Environment

后端 未结 3 480
你的背包
你的背包 2020-12-16 14:34

Does R support proper tail recursion and where can I find documentation about this?

3条回答
  •  时光说笑
    2020-12-16 14:50

    It's quite easy to find out that R does not support tail recursion optimization:

    f <- function(n) {
    if (n != 0) f(n-1)
    }
    f(100000)
    # Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
    

    Had tail calls been optimized to jumps, then this function would have terminated without problems.

提交回复
热议问题