map/filter/reduce/lambda opinions and background unscientificmini-survey
Steven D'Aprano
steve at REMOVEMEcyber.com.au
Wed Jul 6 01:00:04 EDT 2005
I was going to drop the lambda discussion, as it has
been going on and on and on, but Terry's comment
strikes me as so wrong that it needs to be challenged.
Terry Reedy wrote:
> From a certain viewpoint, I would agree. Yet, the word 'lambda' *is* the
> center of most of the fuss. For beginners, it is a minor issue: learn it
> and move on. But for some functionalists, it is a major issue. They
> 'know' that lambda means 'expressionized anonymous function'. And in
> lambda calculus, it is the main actor. But in Python, lambda only means
> anonymous trivial function. It is only an expressionized convenience
> abbreviation for an important but small subset of possible functions. So
> for years, such knowledgeable people have called for and proposed various
> syntaxes for 'proper lambdas' or 'true lambdas', saying pretty clearly that
> what Python has is improper or false. Would there have been so much fuss
> if the keyword had been 'fun' and the word 'lambda' had never appeared in
> the Python docs? I strongly doubt it.
People object to the fact that lambda doesn't allow
statements. They do this, not because they know about
the lambda calculus (I don't!) but because they keep
trying to do things like this:
map(lambda x: if x == 0: 1; else: math.sin(x)/x,
myList)
Hands up who thinks this usage case would disappear if
lambda was called "fun" or "anonymous_function" instead?
> I also suspect that the years of fuss over Python's lambda being what it is
> rather that what it is 'supposed' to be (and is in other languages) but is
> not, has encourage Guido to consider just getting rid of it. I personally
> might prefer keeping the feature but using a different keyword.
Best of all would be if lambda was extended to allow
statements, just like a real made-with-def function.
Although, I worry about syntax and readability. But
then I'm not completely comfortable with the existing
lambda syntax either.
And now, I shall say no more on this issue.
--
Steven.
More information about the Python-list
mailing list