[Python-ideas] A simple proposal concerning lambda
Brice Parent
contact at brice.xyz
Wed Aug 22 12:44:47 EDT 2018
Le 22/08/2018 à 04:12, MRAB a écrit :
> On 2018-08-22 02:38, Elazar wrote:
>> I don't think this change makes sense, but if it's done, there should
>> be another change, with actual implications:
>> There is no way to express the types of the parameters in a lambda -
>> `lambda x: int : x` is obviously a syntax error. Replacing the colon
>> with a different symbol, such as "=>" will make this possible:
>>
>> def x => x
>> def x: int => x
>> def x: int -> int => x
>>
>> It will also give one less meaning to the colon.
>>
> The examples I showed had parens, so your examples could be:
>
> def (x): x
> def (x: int): x
> def (x: int) -> int: x
With or without allowing `def` to be an equivalent of `lambda`, I think
this is a great idea.
To me, someone who understands the following 2 lines:
lambda x, y: x * y
def a(x: float, y: int) -> float: ...
would probably understand the following:
lambda(x: float, y: int) -> float: x * y
(more type hints, I like it!)
More information about the Python-ideas
mailing list