Learn R Programming

trampoline (version 0.1.1)

trm_return: 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

Run this code
# NOT RUN {
trampoline(factorial(13),
           factorial = function(n) {
             if(n <= 1) {
               return(trm_return(1))
             }
             val <- yield(factorial(n - 1))
             return(val * n)
           })
# }

Run the code above in your browser using DataLab