[R] Continuation-parsing / trampoline / infinite recursion problem

Duncan Murdoch murdoch.duncan at gmail.com
Wed Aug 10 19:04:17 CEST 2016


On 10/08/2016 12:53 PM, Thomas Mailund wrote:
> > On 10 Aug 2016, at 13:56, Thomas Mailund <mailund at birc.au.dk> wrote:
> >
> > make_thunk <- function(f, ...) f(...)
>
> Doh!  It is of course this one:
>
> make_thunk <- function(f, ...) function() f(…)
>
> It just binds a function call into a thunk so I can delay its evaluation.

I haven't looked closely at the full set of functions, but this comment:

force(continuation) # if I remove this line I get an error

makes it sound as though you're being caught by lazy evaluation. The 
"make_thunk" doesn't appear to evaluate ..., so its value can change 
between the time you make the thunk and the time you evaluate it.  I 
think you could force the evaluation within make_thunk by changing it to

make_thunk <- function(f, ...) { list(...); function() f(…) }

and then would be able to skip the force() in your thunk_factorial function.

Duncan Murdoch



More information about the R-help mailing list