
On Sun, Oct 3, 2021 at 9:04 AM Abdulla Al Kathiri <alkathiri.abdulla@gmail.com> wrote:
Yeah empty parentheses for parameters-less function is the clear obvious way. Optional parenthesis for single parameter function is a wise choice. In fact, I read C# lambdas and they made really great design choices. I particularly like the statements lambda. How about doing it in Python with the set syntax and a little twist? The last item of the lambda set is the return value. Something like the following: (x, y) => {z = x + y, a = sqrt(z) - 10, a} The return value will be a. Basically if the last item is an expression, the return value will be the value of the expression. If the last item is an assignment statement, then the return value will be None. Only assignment statements and expressions are allowed. Other statements like for loop or with statement are too much anyways for lambda set. C# docs advise against using more than 3 statements in their statements lambda.
I don't like the ambiguity here - using a comma there is going to be annoying with tuple creation. And yes, that would be an extremely likely use-case, for example: people.sort(key=lambda p: (p.salary, p.name, p.id)) IMO assignment statements wouldn't be needed here. For things too complicated for assignment expressions, use def. ChrisA