From luke at stat.uiowa.edu  Thu Mar 12 15:38:34 2009
From: luke at stat.uiowa.edu (luke at stat.uiowa.edu)
Date: Thu, 12 Mar 2009 09:38:34 -0500 (CDT)
Subject: [Rd] E`<`<rrors in recursive default argument references
In-Reply-To: <alpine.LFD.2.00.0903111128340.5957@nokomis.stat.uiowa.edu>
References: <8b356f880903091213o33e27e8di878e4ec574347015@mail.gmail.com>
	<49B5A475.90105@biostat.ku.dk>
	<alpine.LFD.2.00.0903111128340.5957@nokomis.stat.uiowa.edu>
Message-ID: <alpine.LFD.2.00.0903120937410.5957@nokomis.stat.uiowa.edu>

Thanks to Stavros for the report.  This should now be fixed in R-devel.

luke

On Wed, 11 Mar 2009, luke at stat.uiowa.edu wrote:

> Looks like an infinite recursion in R_isMissing, which I think may be
> turned into an infinite loop if the C compiler is doing tail call
> optimization.  I need to understand why this is written the way it is
> and also why another case that I would expect to also have this
> problem does not before identifying the appropriate fix.
>
> luke
>
> On Tue, 10 Mar 2009, Peter Dalgaard wrote:
>
>> 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.
>> 
>> 
>> 
>
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] E`<`<rrors in recursive default argument references
luke at stat.uiowa.edu