That did the trick! I was so focused on not evaluating the continuation that I completely forgot that the thunk could hold an unevaluated value… now it seems to be working for all the various implementations I have been playing around with.
I think I still need to wrap my head around *why* the forced evaluation is necessary there, but I will figure that out when my tired brain has had a little rest. Thanks a lot! Thomas > On 10 Aug 2016, at 19:04, Duncan Murdoch <murdoch.dun...@gmail.com> wrote: > > On 10/08/2016 12:53 PM, Thomas Mailund wrote: >> > On 10 Aug 2016, at 13:56, Thomas Mailund <mail...@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 > > ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.