I sing the praises of lambda, my friend and savior!
Steven Bethard
steven.bethard at gmail.com
Mon Oct 11 15:23:20 EDT 2004
Jeff Shannon <jeff <at> ccvcorp.com> writes:
> Lambdas are hard to read, because they're significantly different,
> syntactically, from any other construct in the language
Yes, they are different (summarizing your points):
* no parens around argument list
* returns a value without the return statement
* contains a single expression, not a sequence of statements
Of course, comparing something like the new decorator syntax to the older
equivalent will also point out a construct that's "significantly different,
syntactically, from any other construct in the language":
@d1
@d2
def f():
pass
as opposed to
def f():
pass
f = d1(d2(f))
Some points (in parallel with yours, as much as possible):
* no parens, but functions are called
* rebinds a name without an assignment statement[1]
* appear as expressions, but act like statements
* appear before a def, but are applied after
I'd contend that lambda syntax is much more in-line with the rest of Python
than decorator syntax. Not that I'm suggesting we get rid of decorator
syntax -- I've already found it useful on a number of occasions. I just
wanted to point out that, all things considered, lambdas are probably more
consistent with Python than decorators are.
Steve
[1] Actually, I believe the function is not bound to a name until after the
decorators are applied, but I don't think it's completely unreasonable to talk
of this as a name rebinding.
More information about the Python-list
mailing list