Multi-line lambda proposal.
Sybren Stuvel
sybrenUSE at YOURthirdtower.com.imagination
Tue May 9 03:08:59 EDT 2006
Kaz Kylheku enlightened us with:
> I've been reading the recent cross-posted flamewar, and read Guido's
> article where he posits that embedding multi-line lambdas in
> expressions is an unsolvable puzzle.
> [...]
> a = lambda(x, y), lambda(s, t), lambda(u, w): u + w
> statement1
> statement2
> lambda:
> statement3
> statement4
I think it's a very ugly solution. If you need multiple lines in your
lambda, use an inner function. If you need a couple of single-line
lambdas and use them in a multi-line expression, assign them to a name
and use that name in their stead.
> a = lambda(x, y):
> return x + y
And what's the advantage of that above this?
def a(x, y):
return x + y
> More examples: lambda defined in a function call argument
>
> a = foo(lambda (x, y)):
> return x + y
>
> Confusing? Not if you read it properly. "A lambda function is
> constructed with arguments x, y and passed to foo, and the result is
> assigned to a. Oh, and by the way, the body of the
> lambda is: return x + y."
I think it's very, very ugly. Use inner functions for that. They are a
much cleaner solution than this.
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
More information about the Python-list
mailing list