From luke at stat.uiowa.edu  Mon Aug 11 14:26:57 2003
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Mon Aug 11 20:26:32 2003
Subject: [Rd] An inconsistency with promise in attributes
In-Reply-To: <19416FD2-CC18-11D7-95DA-0003931A3C9E@stat.wisc.edu>
Message-ID: <Pine.LNX.4.44.0308111319190.1863-100000@itasca2.stat.uiowa.edu>

On Mon, 11 Aug 2003, Saikat DebRoy wrote:

> When an attribute is a delayed expression sometimes it is not forced 
> when it is extracted.
> 
>  > x <- list()
>  > attr(x, "p") <- delay(1)
>  > x
> list()
> attr(,"p")
> <promise: 0x11e4bb8>
>  > val <- attr(x, "p")
>  > val
> [1] 1
>  > attr(x, "p")
> <promise: 0x11e4bb8>
> 
> I am not quite sure whether the above is a bug or not

Promises are not forced when retrieving them from a data structure. I
don't think this is a bug (though I don't think the semantics of user
level access to promises are exactly cast in stone).

> but I think the 
> following is a bug - a promise is supposed to give its value once 
> evaluated!
>
>  > eval(attr(x, "p"))
> <promise: 0x11e4bb8>

This should probably be considered a bug in do_eval (internal eval
would force the promise).  I'd be careful fixing it though as it might
break other things.

Promises are really intended to support lazy evaluation and work best
if they are stored as values of variables in environments.  I'm not
sure I would consider other uses reliable in the long run.

Best,

luke

-- 
Luke Tierney
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
   Actuarial Science
241 Schaeffer Hall                  email:      luke@stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


[Rd] An inconsistency with promise in attributes
Luke Tierney