Steven Bethard wrote:

Jason Zheng wrote:

The true beauty of lambda function is not the convenience of creating functions without naming them. Lambda constructs truly enables higher-order function. For example, I can create a function A that returns a function B that does something interesting according to the arguments that I pass to function A.


But you don't need lambdas to do this. In fact, even in your email, you'll note that you referred to your two functions by name. If you're naming functions, why not use a def statement?


It occurs to me that, in a statically compiled language, function definitions all happen before the program starts, and thus that definition can't be affected by other variables (i.e. an outer function's parameters). In such statically compiled language, a lambda would be very useful simply because it's a *dynamic* function. Of course, in Python *all* functions are created dynamically, therefore (unlike most other languages) the majority of the benefits of lambdas already apply to standard Python functions.

In the couple of years that I've been puzzling over why some people were so fixated upon lambdas as being essential, this hasn't occurred to me before. They really provide scant benefit in Python (which is why I was puzzled by the devotion to them), but they *do* provide a large benefit in other languages. It is, however, quite easy to miss that this relative weakness of Python lambdas is a direct consequence of the fact that a function def is an executable statement rather than a compilation-time declaration.

Jeff Shannon
Technician/Programmer
Credit International

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to