List of Functions

Ben Bacarisse ben.usenet at bsb.me.uk
Mon Mar 28 22:45:58 EDT 2016


Steven D'Aprano <steve at pearwood.info> writes:

> On Mon, 28 Mar 2016 06:51 pm, Jussi Piitulainen wrote:
>
>> Ben Bacarisse writes:
>> 
>>> It's shame that anonymous functions (for that's what's being returned
>>> here -- a function with no name) were born of a subject that used
>>> arbitrary Greek letters for things.  We seem stuck with the mysterious
>>> but meaningless "lambda" for a very simple and useful idea.
>
> I'm not sure that "lambda" is any more mysterious or meaningless than other
> terms used in computing. What's a closure? A trampoline? A future? Mapping?
> Thread? Greenlet? Mantissa? Not to mention terms from mathematics that
> people simply memorise, like "sin", "cos", "power".

Well lambda is more arbitrary than those that include helpful hints to
the technical meaning in the plain English meaning.  What's more, though
they express important concepts they are not all part of Python's
syntax.  Lambda has no helpful meaning and yet has to appear in the
program's text.

Anyway, even it is were exactly like all the other examples, is that a
reason to have more?  I'd argue that we should have as few such words as
possible, especially in the syntax.

If functions were defined

  fun f(x): return x * x

then an anonymous function could be written as a function definition but
the name

  fun (x): return x * x

I suppose you could do that even with "def" but it's a bit less
mnemonic.

There's probably a good reason why this was not done -- maybe it stops
the grammar being LL(1)?  And if lambda's arrived late, and a new
keyword is needed to flag a function expression, then lambda is
appealing to the designer since it's less likely to be in use as an
identifier in existing code than many more meaningful keywords.

<snip>
-- 
Ben.



More information about the Python-list mailing list