From ggrothendieck at gmail.com  Thu Sep 20 02:05:26 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 19 Sep 2007 20:05:26 -0400
Subject: [Rd] copying promise
Message-ID: <971536df0709191705q25128290sb67da39b0f54077a@mail.gmail.com>

1. Is there some way to copy a promise so that the copy has the same
expression in its promise as the original.  In the following we
y is a promise that we want to copy to z.  We
want z to be a promise based on the expression x since y is a
promise based on the expression x.  Thus the answer to the code
below is desired to be z=2 but its 1, 1 and y in the next three
examples so they are not the answer. See examples at end.

2. Is there some way to determine if a variable holds a promise
without evaluating it?

This code relates to question 1.

# example 1
x <- 0
delayedAssign("y", x)
x <- 1
# this forces y which is not what we want
z <- y
x <- 2
z # 1

# example 2
# this connects to z to x via y which is not what we want
#  since if y is forced then z takes its value from that, not x
x <- 0
delayedAssign("y", x)
delayedAssign("z", y)
x <- 1
y
x <- 2
z # 1

# example 3
# this attempts to assign the expression underlying promise y to z
# which seems closest in spirit to what we want
# but it does not work as intended
x <- 0
delayedAssign("y", x)
delayedAssign("z", substitute(y))
x <- 1
y
x <- 2
z # y

> R.version.string # Vista
[1] "R version 2.6.0 alpha (2007-09-06 r42791)"



[Rd] copying promise
Gabor Grothendieck