[Python-Dev] Extended Function syntax (original) (raw)

Armin Rigo arigo@tunes.org
Sat, 1 Feb 2003 09:31:08 -0800 (PST)


Hello,

On Thu, Jan 30, 2003 at 09:02:23PM -0500, Guido van Rossum wrote:

v = e: S

would be equivalent to v = e(T)

Just to throw more oil on the fire, note that this looks quite a lot like

for v in e:
    S

For example, it is quite messy but you can already define 'newproperty' to let you do the following in 2.2:

class X:
   for count in newproperty:
      def get(self):
         return self._count
      def set(self, value):
         self._count = value

Similarily you can "almost" already write the following for locks:

for _ in acquired(lock):
    ...

i.e. you can define acquired() so that the loop is done exactly once, and the lock released at the end. It doesn't really work because you there is no place in acquired() you can put the try:...finally:.

Just-drawing-parallels'ly yours,

Armin.