Skip to content
Prev 132674 / 398506 Next

Understanding eval

On 22/12/2007 3:30 PM, Charilaos Skiadas wrote:
I think this part is wrong.  A better description is:

er is going to be evaluated in an environment where a is set to 5.  The 
parent of that environment is the bar evaluation frame, where er is set 
to be a promise to evaluate a in the global environment.
No, at this point an attempt is made to force the promise.  Promises 
have their own associated environments, and that's where the evaluation 
takes place.  In the case of the er object, the associated environment 
is the one where bar(a) was called, i.e. the global environment.
Diagnosing things like this is hard.  Promises are very difficult things 
to look at:  as soon as you try to do anything with them they get 
evaluated, and there's no way in R code to display them without that.
You can use substitute() to extract the expression part, but there's no 
way to extract the environment part.  Maybe there should be, but it's 
tricky to get the semantics right.  If the function environment() worked 
to extract the environment of a promise, then all sorts of code would 
fail where I really wanted to evaluate the arg before extracting the 
environment.

Duncan Murdoch