Wrap a return value in your recursive function with trm_return()
to have it passed along and returned by your final recursion.
trm_return(x)
x | A value to be returned at the end of all recursions |
---|
x
with added class attribute 'trampoline_return'
trampoline(factorial(13), factorial = function(n) { if(n <= 1) { return(trm_return(1)) } val <- yield(factorial(n - 1)) return(val * n) })#> [1] 6227020800