[Python-ideas] A simple proposal concerning lambda

Jonathan Fine jfine2358 at gmail.com
Wed Aug 22 11:58:17 EDT 2018


I wrote:

> Here is my simple proposal. Enhance Python to allow
>
> >>> hn = def a, b=2, c=3: a ** b / c

I'd like to add a clarification. Here are two proposals.

ONE.  Wherever you could have used 'lambda', you now have a choice.
You can still use 'lambda', or you can use 'def' instead. The
semantics are unchanged.

TWO.  Wherever you could have used 'lambda', you must now use 'def'
instead. The semantics are unchanged.

I'm proposing ONE, not TWO. All existing Python code will continue to
run exactly as before. No Python code will have to be changed. And no
new programming capabilities would be added.

So why do it? In a nutshell, to remove an obstacle. To make DEFerred
expressions easier to understand. Is it worth doing? That's a
cost-benefit analysis. I think the main benefit will be in the docs,
and in teaching people Python.

And does it fit in with the Zen of Python?

> There should be one-- and preferably only one --obvious way to do it.
> Although that way may not be obvious at first unless you're Dutch.

So is having both 'def' and 'lambda' unpythonic? Two ways to do the same thing!

With PEP 572 (see exceptional cases), the following are equivalent:
>>> a = 1
>>> (a := 1)

And we're allowed to use tabs or spaces for indentation (see PEP 666).

So *maybe* having both 'lambda' and 'def' is sufficiently Pythonic.

-- 
Jonathan


More information about the Python-ideas mailing list