better lambda support in the future?
hps3 at seritt.org
Sat Dec 18 01:24:01 CET 2004
Jp Calderone wrote:
> On Fri, 17 Dec 2004 18:16:08 -0500, Terry Reedy <tjreedy at udel.edu> wrote:
>> "Jason Zheng" <jzheng at jpl.nasa.gov> wrote in message
>> news:cpvhee$7uh$1 at nntp1.jpl.nasa.gov...
>> > Steven Bethard wrote:
>> >> 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?
>> They already have: given the fundamental syntax difference between all
>> expressions and expressions within statements, def statements are at
>> the equivalent of lisp lambdas + name binding. When you get an exception
>> traceback, a unique name is more helpful than the pseudoname <lambda>.
>> Isolating the definition of a function in a separate statement also makes
>> it possible to unittest the 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".
>> What puzzles me is 1) why some people apparently think anonymity is good
>> -- is it really that hard to name non-trivial functions? and 2) why some
>> people are so quick to recommend changes to Python before they understand
>> what they can already do (wth def statements, in this case).
> Regarding #1: there must be a great variance between people in the
> difficulty of some aspects of programming. I am always amazed to hear
> from people who have no difficulty picking names for all of their
> functions. This is a task that often stumps me for long minutes. Given
> the obvious profusion of functions in most programs, these minutes
> into hours very quickly. I am always greatful when a lambda lets me avoid
> wasting time on something as irrelevant as giving a name to a short
> function that will be referenced exactly once.
> I am quite envious of those who can easily come up with names for any
> function. Perhaps you lot should go a bit easier on the rest of us and
> let us keep our crutches. After all, Python is a language which is
> supposed to make me more productive by letting me ignore irrelevant
> not force me to waste time on them. Why should this part of the langauge
> be any different?
A lambda should be used for a one-time, one-line-use function that you have
no intention of calling again (anything more would be an
inefficiency--which you profess not to be fond of). It is not terribly
difficult to come up with a name like "get_name()" or the like and stamp a
"def" in front of with a colon on the end. Then again, it is your program,
you can do whatever you like. In my opinion, I don't see how it can be
productive to make code difficult to read and typing the same series of
keystrokes over and over.
More information about the Python-list