Draft Pep (was: Re: Let's Talk About Lambda Functions!)
johnroth at ameritech.net
Mon Aug 5 03:41:24 CEST 2002
"Steve Holden" <sholden at holdenweb.com> wrote in message
news:mAb39.240112$724.131601 at atlpnn01.usenetserver.com...
> "John Roth" <johnroth at ameritech.net> wrote ...
> > "Steve Holden" <sholden at holdenweb.com> wrote ...
> There's probably some detail of your proposal that I'm missing, but I
> do believe it's dead in the water. You could produce a PEP, that at
> would have the merit of making your proposal (and the reasons for its
> rejection, should it be rejected) fully explicit.
Title: Anonymous Functions and Classes
Version: $Revision: 1.0 $
Last-Modified: $Date: 2002/08/03 16:23:15 $
Author: John H. Roth <pythonstuff at jhrothjr.com>
Type: Standards Track
This PEP provides the syntax for generalized anonymous functions and
classes. It provides a replacement for the lambda() function.
There is a continuous interest in generalizing the lambda()
which has significant limitations. Most of the proposals to date
attempted to invent additional syntax to allow fewer restrictions
still maintaining the expression format of lambda().
This proposal short circuits this by using the statement form of
including indentation syntax, within an expression.
It also provides a tutorial function, in that programmers coming to
without experience in a language that includes first class functions
frequently miss the fact that functions and classes can be rebound.
makes the fact explicit.
An anonymous function or class consists of a parenthesized function
class definition, written the same way as a normal function or class
definition, with the following exceptions.
1. The name (the token immediately following the word def or class)
2. The 'def' or 'class' token must be on the line following the
3. The 'def' or 'class' token must be indented sufficiently for the
right parenthesis to close the definition, and still continue the
A very simple example:
x = (
def (x, y):
This example creates an anonymous function and then binds it to the
variable x. If x was found within a class, it would be a method.
0 1 2 3 4 5 6 7
There are no backward compatibility issues. There are no new
and it does not change the interpretation of any currently valid
However, it might break syntax aware editors.
It is not part of this PEP to either remove or depreciate lambda().
There is a significant issue as to whether this is, in fact,
A number of the contributors to the discussion on c.l.py indicated
they preferred lambda() because it limited the size of anonymous
The PEP author agrees with them, in general. This is one of the
why the word 'def' needs to be on the line after the opening
There was a discussion about whether this affected the syntax for
tuples and dictionaries. It does not.
See the discussion on c.l.py beginning in late July, 2002, titled:
Talk About Lambda Functions.
I gratefully acknowledge the help of Fredrick Lundh for the initial
of using the existing statement level def syntax, Bengt Richter for
cutting through the fog by suggesting the use of parenthesis to
the definitions, and Greg Ewing for clarifying what it is that makes
a function a method. Also everyone else who contributed to the
and helped sharpen the focus of the idea.
This document has been placed in the public domain.
More information about the Python-list