I don't expect multiline lambdas to be added to Python. I'm not so sure that that's a bad thing. Regardless, isn't it possible to write your own implementation of multiline lambdas as functions? Wouldn't that be a win-win for everyone?
Anyway, the meat of the idea is this:
def myLambda(args, body):
fun = 'def f(' + args + '):' + body exec fun return f ... ... ... ...
funWithNoName = myLambda('x', '''
print x return(x**2)''') ... ... >>>
[myLambda('x', '''\n print x\n return(x**2)''')(x) for x in range(3)]
0 1 2 [0, 1, 4] There are a few tricks with the indenting, no question. myLambda should be more intelligent than it is, I'm thinking of using regular expressions to do simple indentation checking. Lexical variable scoping would be tricky, but that's not one of a python's strong suits. What am I missing? Josh.
-- http://mail.python.org/mailman/listinfo/python-list