[Python-Dev] anonymous blocks

Phillip J. Eby pje at telecommunity.com
Tue Apr 19 21:39:56 CEST 2005


At 11:55 AM 04/19/2005 -0700, Guido van Rossum wrote:
>I'd recommend this:
>
>tri = self.subcalculation("The quick brown fox jumps over the lazy dog")
>self.disentangle(0x40, tri, self.indent+1)
>
>IMO this is clearer, and even shorter!

What was your opinion on "where" as a lambda replacement?  i.e.

foo = bar(callback1, callback2) where:
     def callback1(x):
         print "hello, "
     def callback2(x):
         print "world!"

I suspect that you like the define-first approach because of your tendency 
to ask questions first and read later.  That is, you want to know what 
callback1 and callback2 are before you see them passed to 
something.  However, other people seem to like to have the context first, 
then fill in the details of each callback later.

Interestingly, this syntax also works to do decoration, though it's not a 
syntax that was ever proposed for that.  e.g.:

foo = classmethod(foo) where:
     def foo(cls,x,y,z):
         # etc.

foo = property(get_foo,set_foo) where:
     def get_foo(self):
         # ...
     def set_foo(self):
         # ...

I don't mind @decorators, of course, but maybe they wouldn't be needed here.


>If we apply this to the anonymous block problem, we may end up finding
>lambda the ultimate compromise -- like a gentleman in the back of my
>talk last week at baypiggies observed (unfortunately I don't know his
>name).
>
>--
>--Guido van Rossum (home page: http://www.python.org/~guido/)
>_______________________________________________
>Python-Dev mailing list
>Python-Dev at python.org
>http://mail.python.org/mailman/listinfo/python-dev
>Unsubscribe: 
>http://mail.python.org/mailman/options/python-dev/pje%40telecommunity.com



More information about the Python-Dev mailing list