From simon.urbanek at r-project.org  Wed Oct 18 02:08:20 2006
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 17 Oct 2006 20:08:20 -0400
Subject: [Rd] Error condition in evaluating a promise
Message-ID: <0359A469-1F7D-4CEF-A408-CCB185D5F90E@r-project.org>

Is there a way to raise an error condition when a promise is  
evaluated such that is can be evaluated again? Right now strange  
things happen when the evaluation fails:

 > delayedAssign("x", if (failed) stop("you have to initialize me  
first!") else foo)
 > foo <- "I'm foo"
 > failed<-TRUE
 > x
Error: you have to initialize me first!
 > x
Error: recursive default argument reference

^^-- from now on x is completely unusable - it has no value (i.e.  
cannot be passed to any function) and yet won't be evaluated again

 > failed<-FALSE
 > x
Error: recursive default argument reference
 > delayedAssign("x", if (failed) stop("you have to initialize me  
first!") else foo)
 > x
[1] "I'm foo"

I'd expect something like
 > failed<-TRUE
 > x
Error: you have to initialize me first!
 > x
Error: you have to initialize me first!
 > failed<-FALSE
 > x
[1] "I'm foo"

Is there a way to achieve that? Intuitively I'd think that this is  
the desired behavior, because currently the promise is sort of  
'broken' after an error (AFAICT the behavior is not documented  
anywhere) - but then, I wasn't messing with promises until now...

Thanks,
Simon




[Rd] Error condition in evaluating a promise
Simon Urbanek