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

Thomas Mailund mailund at birc.au.dk
Wed Aug 10 19:17:05 CEST 2016


But wait, how is it actually changing? And how did calling `cat` make the problem go away? 

Ok, I will go think about it…

Thanks anyway, it seems to do the trick.


> On 10 Aug 2016, at 19:10, Thomas Mailund <mailund at birc.au.dk> 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.
> 
> Thanks a lot!
> 
> 	Thomas
> 
> 
>> On 10 Aug 2016, at 19:04, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> 
>> 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
>> 
>> 
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list