List of Functions

Chris Angelico rosuav at gmail.com
Mon Mar 28 23:33:13 EDT 2016


On Tue, Mar 29, 2016 at 1:45 PM, Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
> 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.

Some languages are exactly like this. I'm not sure what the reason is
for Python's difference, but one possibility is the mess that comes
from having statements inside expressions when indentation is
significant to statements (but free-form in expressions).

ChrisA



More information about the Python-list mailing list