Make 'def' and 'class' usable within expressions

John Roth newsgroups at
Thu Mar 25 16:25:06 CET 2004

"Shane Hathaway" <shane at> wrote in message
news:mailman.373.1080165504.742.python-list at
> In thinking about PEP 318, I came across an idea that might be worth
> pursuing further.  It goes deeper than PEP 318, so it would need its own
> PEP.


One reason no one has responded is that this (at least
the def part) is a very old suggestion that most of us are
bone weary of discussing to death. Also, a lot of the
usual suspects are away at PyCon.

I don't believe there is any major resistance to having
some form of code block to replace the lambda expression.
The major problem is the syntax; as you can see from the
discussion of PEP318 (and 308 if you remember back that
far) having a good syntax is very important to Python

If you can make a contribution to a good syntax for
a code block, I for one would welcome it.

Just to give you a start: Ruby puts a single code block
at the end of the parameter list where it's quite obvious
what it is and where it does not interrupt the flow of reading
the method call. In python, I'd like to be able to put code
blocks wherever I can currently put a function / method

For example:

result = map(lambda: ..., list1, list2, list3)

is readable - barely.

result = map(def (x, y, z):
                      something else
                  list1, list2, list3)

becomes much less readable. This is the problem that
needs to be solved to make code blocks fly.

John Roth

More information about the Python-list mailing list