PEP 312 - Making lambdas implicit worries me, surely it's just the name 'lambda' that is bad...

Alexander Schmolck a.schmolck at gmx.net
Thu Mar 6 21:21:12 CET 2003


Erik Max Francis <max at alcyone.com> writes:

> But that has no bearing on whether Python should also have a compact form
> _for the sole purpose of being compact_.

No one suggests such a thing!  I think there are maybe 4 different levels at
which the mere conciseness of a construct FOO (with a hypothetical, more
verbose alternative, FOO_VERBOSE) can affect a language:

1. FOO is used in the same places as FOO_VERBOSE would, but the code becomes
   more (or less) readable (e.g. ``Bignum(1).add(3)`` 'vs' ``1l + 3``)

2. FOO is used in places where FOO_VERBOSE wouldn't be used, because it is too
   cumbersome (e.g. I'd wager that people more readily use dicts in python
   than HashTables in java).

3. FOO's conciseness affects the design of interfaces of other functions (so
   that they become in some way better, or more general -- e.g. `ifAbsent` vs
   `.get`).

4. FOO's conciseness renders certain hypothetical language extensions
   unnecessary (e.g. control construct syntax, and to some extent even macros,
   in smalltalk).

Now 3 and 4 are of course quite rare, (but all other things being equal),
rather desirable. I think smalltalk's blocks satisfy all 4 (and smalltalk,
although different, is not completely unlike python).

Of course adding a (amongst other things, highly syntactically constrained and
possibly rather restricted) lightweight anonymous function equivalent to
python at this stage might not be worth while the trouble (and increase in
complexity). Also, as you and others remarked, certain syntactic possiblities
might be errorprone or unreadable.

Nonetheless, I think the ability to easily pass chunks of code around (and no
-- lambda does not qualify; or I'd like to see how you rewrite a smalltalk
program by replacing blocks with something like lambda) that close over the
current environment, even if added to python now, is unlikely to affect the
only point 1 (as you seem to imply).

alex




More information about the Python-list mailing list