Make 'def' and 'class' usable within expressions

Shane Hathaway shane at zope.com
Thu Mar 25 10:51:15 EST 2004


John Roth wrote:
> 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
> object.
> 
> For example:
> 
> result = map(lambda: ..., list1, list2, list3)
> 
> is readable - barely.
> 
> result = map(def (x, y, z):
>                       something
>                       something else
>                       return
>                   list1, list2, list3)
> 
> becomes much less readable. This is the problem that
> needs to be solved to make code blocks fly.

That's one of the things I'm trying to achieve, too.  Using this syntax, 
I would write it this way:

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

Shane




More information about the Python-list mailing list