trm_return {trampoline} | R Documentation |
Flag a return value
Description
Wrap a return value in your recursive function with trm_return()
to have it passed along and returned by your final recursion.
Usage
trm_return(x)
Arguments
x |
A value to be returned at the end of all recursions |
Value
x
with added class attribute 'trampoline_return'
Examples
trampoline(factorial(13),
factorial = function(n) {
if(n <= 1) {
return(trm_return(1))
}
val <- yield(factorial(n - 1))
return(val * n)
})
[Package trampoline version 0.1.1 Index]