Re: "groupby" iterator

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 programming: ($1['fred'].x) (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 really support no-argument lambdas. On the other side is the spelled-out form. Perhaps def can really be re-used: def(arglist: expr) as in 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 arguments (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 Layton alexis dot layton at post dot harvard dot edu

Alexis Layton <alexis.layton@post.harvard.edu>:
I think it's ambiguous, too, since it's not clear how far the lambda extends. Is ((&1 + &2), (&1 - &2)) one lambda returning a tuple, or a tuple containing two lambdas? Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+

Alexis Layton <alexis.layton@post.harvard.edu>:
I think it's ambiguous, too, since it's not clear how far the lambda extends. Is ((&1 + &2), (&1 - &2)) one lambda returning a tuple, or a tuple containing two lambdas? Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
participants (2)
-
Alexis Layton
-
Greg Ewing