[Python-Dev] Re: "groupby" iterator
alexis.layton at post.harvard.edu
Wed Dec 3 23:05:41 EST 2003
Greetings illustrious Python developers!
I've been reading the python-dev archives for years now, but the
current discussion of lambda alternatives has finally got me to post.
It seems there is a tradeoff between more general (fully functional,
if you will, pardon the groans) lambda-type constructs, and the
simpler "90%" constructs that have been being batted around here.
One simple style is to "infer" the lambda using positional
arguments, for example:
(&1 + &2.foo())
(this would use "&" as a unary operator which I believe is available?)
Or one could use "$", which begins to look a little like shell
(Or \ if you want to risk being Haskelly....)
This style of construct implies the lambda or function without really
saying it, which may be too magical for Python.
The other main problem with constructs like this are that some number
of current uses of lambda need to ignore arguments; this happens
particularly for GUI callbacks, I think. Also, the syntax doesn't
support no-argument lambdas.
On the other side is the spelled-out form. Perhaps def can really
def(a, b: a + b.foo()) #equivalent to first example
def(a: a['fred'].x) #equivalent to second example
of course, this is very close to lambda in syntax, although it does have
the advantage of a close paren; it can clearly handle all forms of
(keyword, default values (although why would you need...), *, **, etc.)
The hitch there is that the syntax looks different from regular def.
That may be ok, considering the beasts are different....
I'd personally hate to see something equivalent to lambda completely
disappear from the language.
alexis dot layton at post dot harvard dot edu
More information about the Python-Dev