better lambda support in the future?
Steven Bethard
steven.bethard at gmail.com
Fri Dec 17 15:30:36 EST 2004
Jason Zheng wrote:
> I'm wondering why python still has limited lambda support. What's
> stopping the developers of python to support more lisp-like lambda
> function?
This comes up every few weeks on the list. If you haven't already,
check the archives in Google for 'anonymous def' or 'anonymous
function'. The usual response to this question is something along the
lines of "if it's good enough to create a function for, it's good enough
to name".
One of the other big reasons for this type of proposal never making it
far is that, so far, no one has found a syntax that everyone (or even
most people) like. You end up with things like:
x = func or lambda x, y:
# body of lambda func
# indented here
or
x = func or lambda x, y:
# body of lambda func
# indented here
or
x = func or lambda x, y {
# body of lamda func indented
# however you want...
}
or any thousand other varieties.
Even if you could settle the syntax issue, once you've decided that you
really do need a true block in an anonymous function, you're not really
saving much space by not declaring it:
def f(*args):
# body line 1
# body line 2
# ...
# body line N
x = func or f
v.s.
x = func or lambda *args:
# body line 1
# body line 2
# ...
# body line N
so, you save a single line, which is only 1 Nth of the size of your
function (where N is the number of lines in your function body). For a
single or double line function, these savings may be more substantial,
but chances are if your function is only one or two lines, it can be
written as an expression anyway (e.g. using LCs or GEs)...
Do check the archives -- there are a lot of discussions on this topic,
but hopefully the brief commentary above will give you something of an
overview.
Steve
More information about the Python-list
mailing list