From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Mon Mar  9 22:40:06 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Mon, 09 Mar 2009 22:40:06 +0100
Subject: [Rd] E`<`<rrors in recursive default argument references
In-Reply-To: <8b356f880903091213o33e27e8di878e4ec574347015@mail.gmail.com>
References: <8b356f880903091213o33e27e8di878e4ec574347015@mail.gmail.com>
Message-ID: <49B58CB6.6030804@idi.ntnu.no>

Stavros Macrakis wrote:
> Tested in: R version 2.8.1 (2008-12-22) / Windows
>
> Recursive default argument references normally give nice clear errors.
>  In the first set of examples, you get the error:
>
>   Error in ... :
>   promise already under evaluation: recursive default argument
> reference or earlier problems?
>
>   (function(a = a) a      ) ()
>   (function(a = a) c(a)   ) ()
>   (function(a = a) a[1]   ) ()
>   (function(a = a) a[[1]] ) ()
>   (function(a = a) a$x    ) ()
>   (function(a = a) mean(a) )   ()
>   (function(a = a) sort(a) ) ()
>   (function(a = a) as.list(a) ) ()
>
> But in the following examples, R seems not to detect the 'promise
> already under evaluation' condition and instead gets a stack overflow,
> with the error message:
>
>   Error: C stack usage is too close to the limit
>   

when i run these examples, the execution seems to get into an endless
loop with no error messages whatsoever.  how much time does it take
before you get the error?  (using r 2.8.0 and also the latest r-devel).

vQ

>   (function(a = a)  (a)    ) ()
>   (function(a = a)  -a     ) ()
>   

btw. ?'-' talks about '-' as a *binary* operator, but the only example
given there which uses '-' uses it as a *unary* operator.  since '-'()
complains that '-' takes 1 or 2 arguments, it might be a good idea to
acknowledge it in the man page.

>   (function(a = a) var(a) ) ()
>   (function(a = a) sum(a) ) ()
>   (function(a = a) is.vector(a) ) ()
>   (function(a = a) as.numeric(a) ) ()
>
> I don't understand why the two sets of examples behave differently.
>   

a bug in excel?

vQ



[Rd] E`<`<rrors in recursive default argument references
Wacek Kusnierczyk