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

Paul Moore p.f.moore at gmail.com
Wed Mar 27 10:42:17 EDT 2019


On Wed, 27 Mar 2019 at 12:27, Alexey Muranov <alexey.muranov at gmail.com> wrote:
>
> On mer., mars 27, 2019 at 10:10 AM, Paul Moore <p.f.moore at gmail.com>
> wrote:
> > On Wed, 27 Mar 2019 at 08:25, Alexey Muranov
> > <alexey.muranov at gmail.com> wrote:
> >>
> >>  Whey you need a simple function in Python, there is a choice
> >> between a
> >>  normal function declaration and an assignment of a anonymous
> >> function
> >>  (defined by a lambda-expression) to a variable:
> >>
> >>      def f(x): return x*x
> >>
> >>  or
> >>
> >>      f = lambda x: x*x
> >>
> >>  It would be however more convenient to be able to write instead just
> >>
> >>      f(x) = x*x
> >
> > Why? Is saving a few characters really that helpful? So much so that
> > it's worth adding a *third* method of defining functions, which would
> > need documenting, adding to training materials, etc, etc?
>
> Because i think i would prefer to write it this way.

That's not likely to be sufficient reason for changing a language
that's used by literally millions of people.

> (Almost no new documentation or tutorials would be needed IMHO.)

Documentation would be needed to explain how the new construct worked,
for people who either wanted to use it or encountered it in other
people's code. While it may be obvious to you how it works, it likely
won't be to others, and there will probably be edge cases you haven't
considered that others will find and ask about.

Your interest in improving the language is great, but there are a
great many practical considerations in any change, and if you actually
want your idea to progress, you'll need to be prepared to address
those.

Paul



More information about the Python-list mailing list