[Python-3000] Wild idea: Deferred Evaluation & Implicit Lambda

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed May 31 19:05:52 CEST 2006


Marcin 'Qrczak' Kowalczyk <qrczak <at> knm.org.pl> writes:

> 
> Talin <talin <at> acm.org> writes:
> 
> > A 'promise' on the other hand, doesn't need to be explicitly called to 
> > evaluate it. Instead, it automatically evaluates itself whenever it is 
> > 'used'. The problem, of course, is that we haven't defined 'used' very 
> > well. (I.e. if you pass the unevaluated argument to another function, 
> > does it get evaluated or not?)
> 
> I'm afraid that this can't be defined well. I haven't yet seen
> a consistently behaving transparent proxy in any language.
> 

Does that include R?  I've started looking under the hood of R only recently,
and the fact that I was able to use S+ and R for years without even knowing
about promises tells me that these are pretty transparent.

It maybe helpful for the current discussion if someone with more experience than
I would criticize R's approach.

Here is the relevant section from "R Language Definition":

"""
2.1.8 Promise objects

Promise objects are part of R's lazy evaluation mechanism. They contain three
slots: a value, an expression, and an environment. When a function is called the
arguments are matched and then each of the formal arguments is bound to a
promise. The expression that was given for that formal argument and a pointer to
the environment the function was called from are stored in the promise.

Until that argument is accessed there is no value associated with the promise.
When the argument is accessed, the stored expression is evaluated in the stored
environment, and the result is returned. The result is also saved by the
promise. The substitute function will extract the content of the expression
slot. This allows the programmer to access either the value or the expression
associated with the promise.

Within the R language, promise objects are almost only seen implicitly. (In an
upcoming release they will never be visible to R code, as they will always be
evaluated when accessed.) Actual function arguments are of this type. There is
also a delayedAssign function that will make a promise out of an expression.
There is generally no way in R code to check whether an object is a promise or
not, nor is there a way to use R code to determine the environment of a promise. 
"""
<http://cran.r-project.org/doc/manuals/R-lang.html#Promise-objects>




More information about the Python-3000 mailing list