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

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed May 31 04:27:18 CEST 2006


On May 30, 2006, at 8:52 PM, Josiah Carlson wrote:
>
> Really, this boils down to another way of spelling lambda.
>

I almost agree.  The difference between a promise and a lambda is  
that the former can be passed to functions that don't know how to  
deal with callables.  I think an appropriate analogy is the  
difference between a pointer and reference in C++.  In C++ references  
are logically equivalent to (const) pointers, but are not  
interchangeable within the type system. There may be the same reason  
to add promises to python as Stroustrup had for adding references to C 
++: operator overloading <http://www.research.att.com/~bs/ 
bs_faq2.html#pointers-and-references>. A function def foo(x,y):  
return x+y will work fine with x or y or both passed as instances of  
promise[Number], but will not work if either is a lambda.

Another  useful analogy is the difference between ref and proxy from  
the weakref module:

 >>> class X(object):
...   def __add__(self, other):
...             return 42
 >>> x = X()
 >>> p = proxy(x)
 >>> r = ref(x)
 >>> p + p
42
 >>> r + r
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'weakref' and 'weakref'
 >>> r() + r()
42

I think we both agree that adding a keyword would just allow "promise 
(lambda: ...)" be contracted to "lazy: ...".

Returning to the setdefault  proposals, a promise has an advantage  
over lambda because proper action can be taken based on the type of  
the argument without an ambiguity in detecting a callable.

  


More information about the Python-3000 mailing list