Make 'def' and 'class' usable within expressions
newsgroups at jhrothjr.com
Thu Mar 25 19:18:45 CET 2004
"Shane Hathaway" <shane at zope.com> wrote in message
news:mailman.407.1080229887.742.python-list at python.org...
> 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 else
> return x
Now, that's got some real possibilities. At least it doesn't
embed statement indentation problems in the middle of
expression (lack of) indentation.
As a couple of other responders have mentioned, it
doesn't generalize all that well to multiple def's in one
function call, nor does it generalize all that well to having
one embedded in a control statement header (like an if
or for statement).
I personally don't think restricting those cases would be
a significant issue, though. At least, it isn't for me, although
the lack of orthogonality might bother some other people.
More information about the Python-list