[Python-ideas] Enhance definition of functions

Ronald Oussoren ronaldoussoren at mac.com
Tue Jul 30 17:59:54 CEST 2013


On 30 Jul, 2013, at 17:19, Musical Notation <musicdenotation at gmail.com> wrote:

> Yes, I know that multiline lambda will never be implemented in Python, but in many languages it is possible to write an anonymous function without using lambda at all.

"Never" is a long time. AFAIK the main reason why Python doesn't have multi-line lambda's is that nobody has proposed a suitable syntax yet (and not for lack of trying, the archives of this list and python-dev contain a lot of proposals that were found lacking). 

> In JavaScript:
> Instead of "function <name>(<variables>){code}" you can write "var name; name=function(<variables>){code}"

That's just a lambda by another name.

> Python (proposed):
> def func(a,b):
>     print(a+b)
>     return a+b
> 
> becomes
> 
> func=function a,b:
>     print(a+b)
>     return a+b

This has a number a problems, as noted by Matthew this isn't shorter than the corresponding named function. It also introduces a new keyword, and because of that likely breaks existing code (especially because "function" is a fairly common word in IT).  The syntax appears to indicate that the new construct is an expression, if so how would you use it in other contexts where expressions can be used(Such as function arguments, list literals, ...)?  

Ronald
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas



More information about the Python-ideas mailing list