A critic of Guido's blog on Python's lambda

Carl Friedrich Bolz cfbolz at gmx.de
Sun May 7 11:51:14 CEST 2006


Bill Atkins wrote:
[snip]
> 
> Unfortunately, it's *nothing* like a full PyCell implementation.  I
> explained what Cells is above.  It is not merely a spreadsheet - it is
> an extension that allows the programmer to specify how the value of
> some slot (Lisp lingo for "member variable") can be computed.  It
> frees the programmer from having to recompute slot values since Cells
> can transparently update them.  It has to do with extending the object
> system, not with merely setting tables in a hash and then retrieving
> them.

I have not looked at Cells at all, but what you are saying here sounds 
amazingly like Python's properties to me. You specify a function that 
calculates the value of an attribute (Python lingo for something like a 
"member variable"). Something like this:

 >>> class Temperature(object):
...     def __init__(self, temperature_in_celsius):
...         self.celsius = temperature_in_celsius
...     def _get_fahrenheit(self):
...         return self.celsius * 9.0 / 5.0 + 32
...     fahrenheit = property(_get_fahrenheit)
...
 >>> t = Temperature(0)
 >>> t.fahrenheit
32.0
 >>> t.celsius = -32
 >>> t.fahrenheit
-25.600000000000001
 >>> t = Temperature(100)
 >>> t.fahrenheit
212.0

no metaclass hacking necessary. Works also if you want to allow setting 
the property.

Cheers,

Carl Friedrich Bolz




More information about the Python-list mailing list