[Python-ideas] Statements vs Expressions... why?
cliff at develix.com
Mon Sep 15 03:32:12 CEST 2008
On Mon, 2008-09-15 at 13:00 +1200, Greg Ewing wrote:
> Cliff Wells wrote:
> > '-'.join(
> > for j in ( for J in I: YIELD J ): YIELD j
> > )
> Noooooo..... this is getting worse and worse.
> You seem to be thinking of syntax issues as though
> they were purely technical puzzles. The're not --
> they're at least as much human-factors issues
Not that it's terribly relevant to what you say, but:
for J in I: YIELD ( for j in J: YIELD j )
is the corrected form (although YIELD continues to be a placeholder of
In any case, my form does make it slightly more complicated for the
simplest case, but makes it much less complicated for more complex cases
(for the same reasons a plain for-statement can):
x = [ J [ a ]
for a in b
if c ]
x = for a in b:
if c: continue J [ a ]
The complexity has barely increased and yet the second form is already
more readable (the formatting of the first reflects what I typically do
as listcomps get more complex - overkill here but it demonstrates where
Given that the listcomp is the only direct form of looping available as
an expression, I've written some really ugly looking ones. I've
actually taken to commenting open/close brackets simply to help
distinguish them. Not to mention, the listcomp's placement of the
yielded result before the loop and condition only works well when it's a
very simple expression. It doesn't scale well with complexity (not that
I think it was meant to).
> > Certainly more clear and concise, but since (luckily for me this time)
> > we're maintaining backwards-compatibility, that form would still be
> > available.
> But if you keep all the existing syntax as well,
> you haven't simplified anything.
Yes, that's unfortunate. It might, however, obviate the need for newer
More information about the Python-ideas