Thoughts on PEP284

Sean Ross sross at connectmail.carleton.ca
Tue Sep 23 00:44:07 EDT 2003


"David Eppstein" <eppstein at ics.uci.edu> wrote in message
news:eppstein-E0F40C.21003222092003 at news.service.uci.edu...
> In article <SnObb.1581$PT3.257319 at news20.bellglobal.com>,
>  "Sean Ross" <sross at connectmail.carleton.ca> wrote:
>
> > > Some more looping thoughts - this time on integer for loops...
> >
> > Hi.
> > How about the following:
> >
> > for i in 0...10:
> >     # suite
> >
> > where 0...10 works something like xrange(10).
>
> I can't find the message you're replying to, so am responding here only
> to yours.
>
> I personally am uninterested in an integer for-loop syntax that is
> limited to the unintuitiveness of range and xrange's arguments -- 
> they're great for looping forwards through the indices into a list, not
> so great for almost anything else.  If that's all the loop syntax can
> do, why not just keep the current "for i in range(10):" syntax?

Hi.
Right.

Quote from me:
"""
And, after all of that, you could say, well we already have

for i in range(10):
    # suite
...
and you can use xrange()
...

yada, yada, yada.

Whatever.
"""


> "Explicit is better than implicit."
>

Um. Actually, for i in 0...10 _is_ explicit. It explicitly asks for the
integers from 0 thru 9, just as xrange(10) does, but with different syntax.

"where 0...10 works something like xrange(10). "
me, again

I'm familiar with seeing ellipsis used to denote ranges (from textbooks,
other programming languages, and general every day writings), so, to me it's
looks explicit. (Although, I would usually read it as the numbers from 0 to
10, inclusive). But, again, whatever.

> But anyway, PEP 284 has been kind of moribund since Guido dissed it in
> his Parade of PEPs.  I'm not sure what (if anything) it would take to
> revive it,

Sure. I've no intentions of pursuing this syntax proposal.  The PEP was
brought up. A syntax suggestion was made. I didn't much care for those, so I
made others. My interest ends there.

> but convoluted syntax like "for i in 0...10.by(2):" is
> probably not it.

Right.

"This suggestion ... does not provide step control and I can't think of a
clean way to introduce it ..."
me

the by() suggestion was a demonstration of how I could not "think of a clean
way to introduce" step control for the ellipsis based syntax.

> "for i in 0:10:2:" would be more Pythonic, but has a
> little ambiguity problem ("for i in 0:10:2" without the colon seems like
> it should execute the statement "2" ten times) and again doesn't add
> much in readability or power to what we can already do with range.
>

Right.






More information about the Python-list mailing list