I don’t know… that was the behaviour I had yesterday, but on the laptop where I was doing the experiments I updated R from 3.2 to 3.3 earlier today and now the original make_thunk
make_thunk <- function(f, …) function() f(…) also works for me. I don’t know what else I can say to that :) Cheers Thomas On 11 August 2016 at 23:05:29, Duncan Murdoch (murdoch.dun...@gmail.com<mailto:murdoch.dun...@gmail.com>) wrote: On 10/08/2016 1:28 PM, Duncan Murdoch wrote: > On 10/08/2016 1:10 PM, Thomas Mailund wrote: >> 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. > > The original version > > make_thunk <- function(f, ...) function() f(…) > > says to construct a new function whose body evaluates the expression > f(...). It never evaluates f nor ... , so they don't get evaluated > until the first time you evaluate that new function. > > My version containing list(...) forces evaluation of ... . It would > have been even better to use > > make_thunk <- function(f, ...) { list(f, ...); function() f(…) } > > because that forces evaluation of both arguments. > > I suspect you would have problems with > > make_thunk <- function(f, ...) function() do.call(f, list(...)) > > for exactly the same reasons as the original; I'm surprised that you > found it appears to work. I have done some experimentation, and am unable to reproduce the behaviour you described. Using do.call() doesn't affect things. Duncan Murdoch [[alternative HTML version deleted]] ______________________________________________ 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.