[Python-Dev] Recommend accepting PEP 312 -- Simple Implicit Lambda
Nick Coghlan
ncoghlan at gmail.com
Sun Jun 19 09:32:39 CEST 2005
Donovan Baarda wrote:
> Nick Coghlan wrote:
>> And here we see why I'm such a fan of the term 'deferred expression'
>> instead of 'anonymous function'.
>
> But isn't a function just a deferred expression with a name :-)
According to the specific meaning of 'expression' in the Python
grammar? No.
> Isn't that because lambda's have the limitation of not allowing
> statements, only expressions? I know this limitation avoids side-effects
> and has significance in some formal (functional?) languages... but is
> that what Python is?
Personally, I believe it has to do with two things, one practical and
one more stylistic/philosophical.
Firstly, Python uses significant whitespace between statements, and to
delineate sections of compound statements. Within expressions however,
whitespace is essentially insignificant (except where it affects the
tokenisation). Trying to embed suites (where whitespace can be
significant) inside expressions (where whitespace is generally
insiginificant) tends to result in a horrible mess, or else some
rather unPythonic concepts (e.g. using something other than
indentation to demarcate the suite).
Secondly, trying to cram too much functionality into a single line is
a questionable activity. The 'deferred expression' approach taken with
lambdas is a hint that if the thing you're trying to defer is more
complex than a single expression, it may be worth giving it a proper
name via 'def'.
> In the Python I use, lambda's are always used where
> you are too lazy to define a function to do it's job.
In simple cases, naming the expression to be deferred results in it
gaining a prominence it doesn't deserve, possibly obscuring the
purpose of the main statement.
In such cases, deferred expressions are a better solution - it's
merely unfortunate that Python's current syntax for the practice
anything to write home about.
> To me, anonymous procedures/functions would be a superset of "deferred
> expressions", and if the one stone fits perfectly in the slingshot we
> have and can kill multiple birds... why hunt for another stone?
Because there is already a solution for the large birds - *named*
functions.
Unfortunately, using a named function for a simple deferred expression
is like using a catapult to kill a canary.
> If there really is a serious practical reason why they must be limited
> to expressions, why not just raise an exception or something if the
> "anonymous function" is too complicated...
You'd still need a definition of 'too complicated' - which we already
have for deferred expressions. Specifically "unable to be expressed as
a single Python expression".
>> Anyway, the AlternateLambdaSyntax Wiki page has a couple of relevant
>> entries under 'real closures'.
>
> Where is that wiki BTW? I remember looking at it ages ago but can't find
> the link anymore.
http://wiki.python.org/moin/AlternateLambdaSyntax
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list