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

Ben Finney ben+python at benfinney.id.au
Wed Mar 27 20:11:20 EDT 2019


Alexey Muranov <alexey.muranov at gmail.com> writes:

> It would be however more convenient to be able to write instead just
>
>    f(x) = x*x

That's not an anonymous function then, is it? You want to assign a name
to that function, and (to be useful in development tools, such as a
stack trace) the function needs to know its own name.

The way to do that is, as you point out, the ‘def’ statement:

    def f(x):
        return (x * x)

What does that prevent you from doing? It will need to be pretty
significant improvement to be considered as a change to language syntax.

> Have this idea been discussed before?

Too many times to count :-)

-- 
 \       “Theology is the effort to explain the unknowable in terms of |
  `\                         the not worth knowing.” —Henry L. Mencken |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list