[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Syntax for one-line "nonymous" functions in "declaration style"

On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov <alexey.muranov at>
> On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy <tjreedy at> wrote:
> > Throwing the name away is foolish.  Testing functions is another
> > situation in which function names are needed for proper report.
> My idea however was to have it as an exact synonyme of an assignment of
> a lambda. Assignment is an assignment, it should not modify the
> attributs of the value that is being assigned.

There could perhaps be a special case for lambda expressions such that,
when they are directly assigned to a variable, Python would use the
variable name as the function name. I expect this could be accomplished by
a straightforward transformation of the AST, perhaps even by just replacing
the assignment with a def statement.

Since this could just as easily be applied to lambda though, I'm afraid it
doesn't offer much of a case for the "f(x)" syntactic sugar.