[Python-Dev] Recommend accepting PEP 312 -- Simple Implicit Lambda
Kay Schluehr
kay.schluehr at gmx.net
Sun Jun 19 13:47:54 CEST 2005
Donovan Baarda wrote:
> I don't get what the problem is with mixing statement and expression
> semantics... from a practial point of view, statements just offer a
> superset of expression functionality.
>
> 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...
>
> I did some fiddling and it seems lambda's can call methods and stuff
> that can have side effects, which kinda defeats what I thought was the
> point of "statements vs expressions"... I guess I just don't
> understand... maybe I'm just thick :-)
The whole point is that you are able to do all the basic control flow
operations like IF, FOR and WHILE using simple expressions ( like in
Pythons lambda ), the lambda statement itself and recursion. Therefore
lambda expressions constitute a Turing complete language and they also
do so in Python. Different to many FP languages lambda plays no central
role in Python because statements won't be reduced to lambda expressions
( or some kind of ). They are merely an add-on.
Reduction provides often the advantage to make expressions/statements
scriptable what they are not in Python. Python is strong in scripting
classes/objects ( a big plus of the language ) but you can't simply use
the language to prove that
lambda x,y: x+y*y
lambda x,y: y**2+x
are essentialy the same functions with different implementations [1]. I
think this is a severe lack of expressibility and has nothing to do with
the silly objection that one has to write one more line for a simple
callback - o.k. I admit that I'm lazy too ;)
Regards,
Kay
[1] Not without hacking the parse tree. Doing so one might finally end
up accessing the expression in a simple modifieable manner:
>>> (lambda x,y: x+y*y).expr
('+',(x,'*',(y,y)))
>>> (lambda x,y: y**2+x).expr
('+',(('**',(y,2)),x))
More information about the Python-Dev
mailing list