Tail recursion on R Statistical Environment

后端 未结 3 481
你的背包
你的背包 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.

    0 讨论(0)
  • 2020-12-16 15:05

    This reference, found easily with Google, suggests that R does not support tail recursion and explains why.

    0 讨论(0)
  • 2020-12-16 15:09

    No, R does not support tail recursion.

    0 讨论(0)
提交回复
热议问题