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. 

Abdulla


Sent from my iPhone

> On 2 Oct 2021, at 8:33 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> 
> On 2021-10-02 08:59, Abdulla Al Kathiri wrote:
>> Let’s say I want to write a lambda function with no arguments that’s 
>> connected to a button in GUI coding, will 
>> blabla.connect(()=>print(“clicked”)) be used or will 
>> blabla.connect(=>print(“clicked”)) be used?
>> 
> In the case of C#, the parentheses are optional if there's only one 
> parameter, so:
> 
>     () => ...
> 
>     (x) => ... or x => ...
> 
>     (x, y) => ...
> 
>     (x, y, z) => ...
> 
> etc.
> 
>> > On 30 Sep 2021, at 7:53 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
>> > > On 2021-09-30 07:21, Chris Angelico wrote:
>> >>> On Thu, Sep 30, 2021 at 4:19 PM Steven D'Aprano <st...@pearwood.info> 
>> >>> wrote:
>> >>> >>>> On Wed, Sep 29, 2021 at 02:09:03PM -0700, Guido van Rossum wrote:
>> >>> > Over in typing-sig we're considering a new syntax for callable *types*,
>> >>> > which would look like (int, int, str) -> float. A matching syntax for
>> >>> > lambda would use a different arrow, e.g. (x, y, z) => x+y+z.
>> >>> >>> I like arrow operators :-)
>> >>> >>> But I fear that it will be too easy to misread `=>` as greater than 
>> >>> >>> or
>> >>> equal to, especially when skimming code.
>> >>> >>> Assuming that they need to be different arrows, how do you feel about
>> >>> `->` for types and annotations, and `-->` for lambdas? Or `->>`?
>> >>> >> JavaScript uses => for functions, and the confusion with ">=" doesn't
>> >> seem to be a major problem with it.
>> > C# also uses "=>".
>> > 
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/UYGJOUJJGG72O3TRAK5JB7JX2AO2YQGF/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LVOXHW2KWQXU32SMFXE4ZH43S7JJUIKY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to