lambda (and reduce) are valuable

David Isaac aisaac0 at verizon.net
Fri Dec 9 18:19:27 EST 2005


>>>     Jibes against the lambda-clingers lead eventually to serious
>>>     questions of style in regard to variable namespacing,
>>>     lifespan, cleanup, and so on:
>>>
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ad0e15cb6b8f2c32/

Alan Isaac <aisaac0 at verizon.net> wrote:
>> #evaluate polynomial (coefs) at x using Horner's rule
>> def horner(coefs,x): return reduce(lambda a1,a2: a1*x+a2,coefs)

"Cameron Laird" <python-url at phaseit.net> wrote in message
news:dn7ibf$id0$1 at lairds.us...
> I *think* you're supporting a claim
> about the value of lambda with a specific example.  Do I have that
> right?  Are you saying that your definition of horner() would suffer
> greatly without lambda?

It is a simple example of how lambda and reduce can be very expressive.
Anyone who understands Horner's rule can see at a glance that this code
implements it.  Anyone who has bothered to learn what lambda and reduce
do can see at a glance what the algorithm is.

It just cannot get simpler or more expressive.

Suffer greatly?  Surely not.  For "suffer greatly" you would probably need
to turn to people who do a lot of event-driven GUI programming.
But suffer, yes.  Simplicity and expressiveness are valuable.
That is the point.

Cheers,
Alan Isaac






More information about the Python-list mailing list