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

2016-08-11 Thread Thomas Mailund
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 :) Cheer

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

2016-08-11 Thread Duncan Murdoch
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 implementat

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

2016-08-10 Thread Thomas Mailund
Yes, I am aware of this situation and I agree that it is better to force f. I was simply trying to figure out why it was necessary in this particular program where the only repeated assignment anywhere in the code is in trampoline, in a scope none of the thunks can see. What ever my problem was

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

2016-08-10 Thread Duncan Murdoch
On 10/08/2016 2:39 PM, Thomas Mailund wrote: Ok, I think maybe I am beginning to see what is going wrong... Explicitly remembering the thunk parameters in a list works fine, as far as I can see. make_thunk <- function(f, ...) { remembered <- list(...) function(...) do.call(f, as.list(reme

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

2016-08-10 Thread Thomas Mailund
  Ok, I think maybe I am beginning to see what is going wrong... Explicitly remembering the thunk parameters in a list works fine, as far as I can see. make_thunk <- function(f, ...) {   remembered <- list(...)   function(...) do.call(f, as.list(remembered)) } thunk_factorial <- function(n, con

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

2016-08-10 Thread Thomas Mailund
  Well, they stay at 3 when I call cat (except for the final step going down in they recursion where `identity` is called, where they are 4). They do that both when I evaluate ... in the `make_thunk` function and when I don’t. But then, when I call `cat` it also worked before. I cannot keep `cat

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

2016-08-10 Thread William Dunlap via R-help
You may gain some understanding of what is going on by adding the output of sys.nframe() or length(sys.calls()) to the cat() statement. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 10, 2016 at 9:59 AM, Thomas Mailund wrote: > An alternative implementation, closer to what I need when

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

2016-08-10 Thread Thomas Mailund
  I am not sure I can see exactly how the parameters are changing at all, regardless of which of the versions I am using. Nowhere in the code do I ever modify assign to a variable (except for defining the global-level functions). I think my problem is that I don’t really understand ... here. I

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

2016-08-10 Thread Duncan Murdoch
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

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

2016-08-10 Thread Thomas Mailund
On 10 Aug 2016, at 19:15, Bert Gunter mailto:bgunter.4...@gmail.com>> wrote: make_thunk is probably unnecessary and apparently problematic. I think you could use do.call() instead, as do.call(f,list(...)) . Yes, make_thunk <- function(f, ...) function() do.call(f, list(...)) also works as f

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

2016-08-10 Thread Thomas Mailund
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 wrote: > > > That did the trick! > > I was so focused on not evaluating the continu

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

2016-08-10 Thread Bert Gunter
make_thunk is probably unnecessary and apparently problematic. I think you could use do.call() instead, as do.call(f,list(...)) . -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Blo

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

2016-08-10 Thread Thomas Mailund
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* th

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

2016-08-10 Thread Duncan Murdoch
On 10/08/2016 12:53 PM, Thomas Mailund wrote: > On 10 Aug 2016, at 13:56, Thomas Mailund 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.

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

2016-08-10 Thread Thomas Mailund
An alternative implementation, closer to what I need when I have more than one recursion in each step, but still using factorial as the example, is this one: thunk_factorial <- function(n, continuation = identity) { force(continuation) # if I remove this line I get an error cat("call: ", n, "

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

2016-08-10 Thread Thomas Mailund
> On 10 Aug 2016, at 13:56, Thomas Mailund 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. Sorry Thomas _

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

2016-08-10 Thread Thomas Mailund
  Oh, I see that the make_thunk function is missing in my example. It is just this one make_thunk <- function(f, ...) f(...) On 9 August 2016 at 21:57:05, Thomas Mailund (mail...@birc.au.dk(mailto:mail...@birc.au.dk)) wrote: > [I’m really sorry if you receive this mail twice. I just notice

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

2016-08-09 Thread Thomas Mailund
[I’m really sorry if you receive this mail twice. I just noticed I had sent it from a different account that the one I signed up to the mailing list on and I don’t know if that means it will be filtered; at least I haven’t received it myself yet.] I am playing around with continuation-passing