From p.dalgaard at biostat.ku.dk  Tue Mar 10 00:21:25 2009
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Tue, 10 Mar 2009 00:21:25 +0100
Subject: [Rd] E`<`<rrors in recursive default argument references
In-Reply-To: <8b356f880903091213o33e27e8di878e4ec574347015@mail.gmail.com>
References: <8b356f880903091213o33e27e8di878e4ec574347015@mail.gmail.com>
Message-ID: <49B5A475.90105@biostat.ku.dk>

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
> 
>   (function(a = a)  (a)    ) ()
>   (function(a = a)  -a     ) ()
>   (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.

Ouch!!!

This shouldn't happen, I'm pretty sure. In particular not the apparently 
unstoppable loop under Linux. Thanks for pointing it out.


-- 
    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] E`<`<rrors in recursive default argument references
Peter Dalgaard