[Python-ideas] Statements vs Expressions... why?

Cliff Wells cliff at develix.com
Sun Sep 14 11:10:42 CEST 2008


On Sun, 2008-09-14 at 01:54 -0700, Cliff Wells wrote:
> On Sun, 2008-09-14 at 01:44 -0700, Cliff Wells wrote:
> 
> > 
> > I'm probably replying way too fast (in fact, I know I am), but I have
> > two thoughts on this:
> > 
> > 1) it seems to alter the semantics of "continue" too much when
> > considered against current syntax, but...
> > 
> > 2) with the new syntax, it seems not too bad because
> > 
> > j = range(3)
> > for i in j: i  # evaluates to []
> > for i in j: continue # evaluates to []
> > for i in j: continue i # evaluates to [0,1,2] 
> 
> Bah, I knew I was replying too fast.  I'm thinking that "continue" would
> be redefined to mean "yield value and continue" which means that
> 
> for i in j: continue # evaluates to [ None, None, None ] not []
> 
> would seem the most consistent, but I fear it might be less practical
> (as it would create problems trying to use for/continue inside other
> expressions, although the effect when for/continue is used as a
> statement remains fine).

It would *have* to evaluate to an empty list otherwise this code:

for i in range(10000000):
    continue

would create a huge list as a side-effect.

So the question is, does this seem too inconsistent?  Clearly returning
[None, None, None] fits nicely with how yield currently works but it's
not going to work in this case.

Cliff




More information about the Python-ideas mailing list