[Python-ideas] a new lambda syntax

starwing weasley_wx at qq.com
Mon Oct 19 15:33:06 CEST 2009


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






More information about the Python-ideas mailing list