From luke at stat.uiowa.edu  Mon Sep 24 15:00:02 2007
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Mon, 24 Sep 2007 08:00:02 -0500 (CDT)
Subject: [Rd] Inspecting promises
In-Reply-To: <971536df0709231831p52ef05cax5e5e66390b3bacee@mail.gmail.com>
References: <971536df0709231831p52ef05cax5e5e66390b3bacee@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0709240752570.26429@nokomis.stat.uiowa.edu>

Please keep in mind that while lazy evaluation and delayedAssign are
documented parts of the language, promises are an internal
implementation mechanism that is subject to change.  In particular the
fact that substitute behaves the way it does is a coincidence of the
current implementation that may very well change.  Currently, for
example, the use of promises to make substitute work means promises
need to be kept around once thei are forced.  This is inefficient in
several ways and may need to be fixed at some point.

It may well be useful to provide some reflection mechanisms for
examining environments, but there are more issues to consider than
pending evaluations (active bindings for example). I'm not sure when
this will rise to the top of anyone's priority list for
implementation.

luke

On Sun, 23 Sep 2007, Gabor Grothendieck wrote:

> Is there some way of displaying the expression and evaluation environment
> associated with a promise?   I have found the following:
>
>> # first run these two commands to set up example
>> e <- new.env()
>> delayedAssign("y", x*x, assign.env = e)
>
>> # method 1.  shows expression but not evaluation environment
>> str(as.list(e))
> List of 1
> $ y: promise to  language x * x
>
>> # method 2. shows expression but not evaluation environment
>> substitute(y, e)
> x * x
>
> which shows two different ways of displaying the expression
> associated with a promise but neither shows the evaluation
> environment.  The first technique may actually be a bug in
> R based on previous discussion on r-devel.
>
> Is there a way to display both the expression and the evaluation
> environment associated with a promise.  Its a bit difficult to debug
> code involving promises if you can't inspect the objects you are
> working with.
>
>> R.version.string # Vista
> [1] "R version 2.6.0 beta (2007-09-19 r42914)"
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
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] Inspecting promises
Luke Tierney