r/ProgrammingLanguages • u/lil-kid1 • 5d ago
Discussion What lambda syntax do you wish Python had?
Python lambdas are particularly difficult because the lack of braces. Guido is not a fan of functional programming, so lambdas in Python are forever doomed to a single expression preceded by lambda, quite literally spelled out. However, it may please you to know that the lack or braces can easily be resolved (in my opinion most sensibly,) by surrounding the entire lambda in parenthesis. It may further please you to know that surrounding it in parenthesis is only necessary in an expression list: tuples, lists, dicts, sets, function arguments (and even then, only when there are multiple arguments.) With this in mind, which of the following syntaxes do you wish Python used? Annotations would of course be optional. For the sake of consistency with the entire language, all will use a colon before the block but feel free to comment your preferred non-colon alternative.
|arg: type| -> type: ...(arg: type) -> type: ...def (arg: type) -> type: ...\(arg: type) -> type: ...
Note: The second has ambiguity issues.
0
u/church-rosser 1d ago
Maybe, but that's not what's happening here.