From ripley at stats.ox.ac.uk  Mon Aug 11 20:40:51 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon Aug 11 20:40:34 2003
Subject: [Rd] An inconsistency with promise in attributes
In-Reply-To: <Pine.LNX.4.44.0308111319190.1863-100000@itasca2.stat.uiowa.edu>
Message-ID: <Pine.LNX.4.44.0308111935100.15021-100000@gannet.stats>

On Mon, 11 Aug 2003, Luke Tierney wrote:

> 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).

I noticed that ?delay says

     A _promise_ to evaluate the expression. The value which is
     returned by 'delay' can be assigned without forcing its
     evaluation, but any further accesses will cause evaluation.

and I take that to mean that printing an expression should force promises.
(Not that the help page is definitive, but still I've wondered before why 
print() did not force promises.)

Brian

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] An inconsistency with promise in attributes
Prof Brian Ripley