I'm trying to dig up past threads about alternatives to lambda because I would be astonished if "def" hadn't been considered and rejected for some reason. What I've found so far is this unreassuring post from Guido back in 2006 <https://mail.python.org/pipermail/python-dev/2006-February/060415.html>
On Tue, Aug 21, 2018 at 4:27 PM, Jonathan Fine <jfine2...@gmail.com> wrote: > Here's what I call a simple proposal. Some people might find it > outrageous. Today is not 1st April. > > > BACKGROUND > ============ > Many Python users don't like the name lambda. But many Python users > don't want any change here. This is true because there are millions of > Python users, and even 100 is many. And it's hard to introduce a new > keyword, which might break existing code. (And perhaps even worse, > break the community.) > > https://wiki.python.org/moin/LocalUserGroups > > There about 1,637 Python user groups worldwide in almost 191 cities, 37 > countries and over 860,333 members. > > > SOME VALID PYTHON > ================== > Here's some valid Python, defining two functions fn and gn, that are > virtually identical. > > >>> def fn(a, b=2, c=3): > ... return a ** b / c > >>> fn > <function fn at 0x7ff815dddf28> > > >>> gn = lambda a, b=2, c=3: a ** b / c > >>> gn > <function <lambda> at 0x7ff815e2bbf8> > > Notice that fn and gn have the same type, and differ by name. > > >>> type(fn), type(gn) > (<class 'function'>, <class 'function'>) > >>> fn.__qualname__, gn.__qualname__ > ('fn', '<lambda>') > > And that we can modify the display name of fn and gn. > > >>> fn.__qualname__ = 'my_fn' > >>> fn > <function my_fn at 0x7ff815dddf28> > > >>> gn.__qualname__ = 'my_gn' > >>> gn > <function my_gn at 0x7ff815e2bbf8> > > > MY SIMPLE PROPOSAL > ==================== > > Here is my simple proposal. Enhance Python to allow > > >>> hn = def a, b=2, c=3: a ** b / c > >>> hn > <function at 0x7ff811e57620> > >>> hn.__qualname__ > '' > > MIGRATION > ========== > > Migration of code would require only a keyword substitution of > 'lambda' by 'def'. > > And in the docs > 1. Note that 'def' can mean 'define' (the current use), and also > 'defer' (evaluation of an expression). > 2. In the first case, we have a *named function*. In the second case, > we have an *expression function*. > > This idea came to me while writing: > https://mail.python.org/pipermail/python-ideas/2018-August/052880.html > > -- > Jonathan > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/