Thoughts on PEP284

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Fri Sep 26 16:32:07 EDT 2003


On Fri, 26 Sep 2003 17:43:11 GMT, Andrew Koenig <ark at acm.org> wrote:

>Stephen> I doubt the need for exclusive ranges in integer for loops. I
>Stephen> also doubt the need for switching between different range
>Stephen> systems (inclusive, exclusive, half-open). IMO there is more
>Stephen> confusion than anything down those routes.
>
>Really?  I would expect a common usage to be:
>
>        for 0 <= index < len(list):
>             do something with list[index]

We have half-open already. I was commenting on the need for supporting
several *different* schemes. Basically...

I don't see the need to support this case...

  for 0 < index < len(list) :  #  ie exclusive

And think that supporting one or the other of these two would be
sufficient...

  for 0 <= index < len(list) :  #  ie half-open
  for 0 <= index <= len(list) :  #  ie inclusive

And can I think of any languages that support a variety of cases?

C, C++, Java etc support both half-open and inclusive with a simple
change of the continuation condition operator.

The Pascal, Modula 2, Ada etc seem to stick with inclusive IIRC.

These 'limitations' don't really seem to cause a problem, though.


That said, with all this reverse iteration stuff we've been discussing
recently, there is a point to make. If half-open ranges are common,
then the 'reverse' half-open case may be useful too...

  for len(list) > index >= 0 :

It's basically a case of symmetry. It avoids the need for all those
'-1' corrections we've been stressing about just recently.


Well, who says I can't have second thoughts.

Still not keen on the syntax, though. And as exclusive ranges have no
apparent frequent use, and rewriting inclusive ranges as half-open
ranges is not really a problem, so really we only need to support the
two half-open cases. And that is really what all the backward
iteration stuff is about.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list