[Python-Dev] Re: "groupby" iterator

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Dec 2 19:16:30 EST 2003


Robert Brewer <fumanchu at amor.org>:

> So that instead of (lambda self: self.foo), you'd end up with
> (rightcurry(getattr, 'foo'))

At the expense of a large drop in readability.

We seem to be talking about two different things in this thread, speed
and readability. The nice thing about the "attrgetter.x" etc. idea is
that it has the potential to provide both at once.

The nasty thing about it is that it smells a bit too much like a
clever trick. It's really abusing the syntax to make it mean something
different from what it usually means.

I think I like the idea of optimising lambda, but that doesn't do
anything for the readability. So, how about a nicer syntax for lambda?
Maybe along the lines of

   x -> x.something

A bonus of introducing a new lambda syntax is that it would provide
the opportunity to give it early-binding semantics for free variables,
like generator expressions. The old lambda would have to be kept
around for a while for programs relying on the old semantics, but it
could be deprecated, and removed in 3.0.

Jeepers, *another* PEP to get around to writing one day...

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+



More information about the Python-Dev mailing list