[Python-ideas] a new lambda syntax

Masklinn masklinn at masklinn.net
Mon Oct 19 15:43:59 CEST 2009


On 19 Oct 2009, at 15:33 , starwing wrote:
> In ruby, we can add a lambda function into a function call. but it's a
> little ugly:
>
> [1,2,3,4].each { |x|
> print x
> }
>
>
> but, it really convenient. current lambda only support single line
> syntax. it's not very good. maybe we can add a new syntax:
> call: primary "(" argument-list ")" [ "lambda" parameter-list ":"  
> suite ]
>
> the postfix lambda will translate to a single "function" object, and
> pass to the &arg parameter of function. so the function call will  
> become
> func(*arg1, **arg2, &arg3)
>
> for example, we can write this:
>
> def print_list(*lists, &func = lambda x: true):
> for item in lists:
> map(a) lambda x:
> if func(x):
> print x
>
>
> call with:
> print_list([1,2,3], [1,2]) lambda x:
> if x % 2: return True
> else return False
>

This is not going to end well.

Also,
http://mail.python.org/pipermail/python-ideas/2007-December/001279.html
http://mail.python.org/pipermail/python-ideas/2008-April/001522.html
http://mail.python.org/pipermail/python-ideas/2008-November/002340.html

The BDFL has disliked every proposal so far, and due to the Ruby- 
inspired weirdness and magic of this one I really don't see him liking  
it any better than the ones that came before.

-m



More information about the Python-ideas mailing list