Multiple statement lambda expressions
What about this? lambda x, y: a = sum(x)/len(x); b = sum(y)/len(y); (a+b)/2;; The double-semicolon notation can also replace indentation for grouping of statements: y=0 for x in list: y=2*y+x if y%13==0: y=12;;;;
Can you give an example where having multiple statements on one line wouldn't be less readable and debuggable? If either len(x) or len(y) were zero, a ZeroDivisionError would be thrown, but you wouldn't know whether or not it was x or y that caused it. Would a or b in the local scope be overwritten? Does the final "statement" have to be an expression or would None be returned as with named functions? Are we allowing return statements, e.g. "return (a+b)/2", which would allow returning early? If so, wouldn't it be more consistent with named functions to only be able to return with a return statement? Would all lambdas be required to end in double-semicolons? Single-statement ones? No-statement ones? If it were required, this would (in my opinion, unnecessarily) break old code. And if it didn't require it, wouldn't both of the following lines be valid: lambda x: x - 1; x + 3; lambda x: x - 1; x + 3;; which could be tricky to debug if one accidentally included/excluded an extra semi-colon. I think this idea needs some fleshing out. On Sat, Aug 24, 2013 at 10:24 PM, Musical Notation < musicdenotation@gmail.com> wrote:
What about this? lambda x, y: a = sum(x)/len(x); b = sum(y)/len(y); (a+b)/2;; The double-semicolon notation can also replace indentation for grouping of statements:
y=0 for x in list: y=2*y+x if y%13==0: y=12;;;; _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
On 25 August 2013 15:01, Michael Mitchell <epsilonmichael@gmail.com> wrote:
I think this idea needs some fleshing out.
Independent of the readability issues associated with any proposal to expand lambdas out to full function definitions, Guido has mandated that it shall be possible to parse Python's grammer with an LL(1) parser. There's no way such a parser can look ahead far enough to see the double semi-colon to change how earlier semi-colons are parsed. PEPs 403 and 3150 are still the current "state of the art" for proposals to add the equivalent of multi-line lambda capabilities to Python, and both still have fairly major flaws (which is why they're Deferred rather than under active development). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On 25/08/13 13:24, Musical Notation wrote:
The double-semicolon notation can also replace indentation for grouping of statements:
y=0 for x in list: y=2*y+x if y%13==0: y=12;;;;
I don't understand what you mean by "replace indentation". You haven't replaced indentation, it is still there. Also, I think that any proposal to remove significant indentation will go nowhere. Python's philosophy is that significant indentation is a feature, not a bug to be removed. You might as well propose getting rid of functions. -- Steven
participants (4)
-
Michael Mitchell
-
Musical Notation
-
Nick Coghlan
-
Steven D'Aprano