Skip to content
Prev 363268 / 398502 Next

Continuation-parsing / trampoline / infinite recursion problem

?
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 would expect these two cases, with and without a thunk, to give me the same output, but they clearly do not.

x <- function(...) eval(substitute(alist(...)))
x(a = 2, b = 3)
x(c = 4, d = 5)

xx <- function(...) function() eval(substitute(alist(...)))
xx(a = 2, b = 3)()
xx(c = 4, d = 5)()

The first gives me the parameters and the second just ? back.

How is the thunk actually seeing ... and why does it work with do.call and not with direct call?

library(pryr)
xxx <- function(...) function() do.call(eval %.% substitute %.% alist, list(...))
xxx(a = 2, b = 3)()
xxx(c = 4, d = 5)()

gives me the same results as the xx case, so it is not the do.call that does it, even though that works in my examples.

With

xxxx <- function(...) { list(...) ; function() eval(substitute(alist(...))) }
xxxx(a = 2, b = 3)()
xxxx(c = 4, d = 5)()

it is the same.


Explicitly naming the parameters, of course works fine

y <- function( ...) { params <- list(...) ; function() params }
y(a = 2, b = 3)()
y(c = 4, d = 5)()

Here I get the expected lists out.

I guess I just shouldn?t be using ... in an inner function that refers to the parameters in an outer function. I?m not even sure what that should be expected to do and I certainly do not understand what is happening :)

Explicitly remembering the parameters seems to work fine, though.

Cheers
	Thomas
On 10 August 2016 at 19:28:43, Duncan Murdoch (murdoch.duncan at gmail.com(mailto:murdoch.duncan at gmail.com)) wrote:

            

Thread (18 messages)

Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 9 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Duncan Murdoch Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Bert Gunter Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Duncan Murdoch Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 William Dunlap Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Duncan Murdoch Continuation-parsing / trampoline / infinite recursion problem Aug 10 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 10 Duncan Murdoch Continuation-parsing / trampoline / infinite recursion problem Aug 11 Thomas Mailund Continuation-parsing / trampoline / infinite recursion problem Aug 11