<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 2, 2015 at 2:36 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sun, Feb 01, 2015 at 10:18:33PM +0100, Todd wrote:<br>
> On Feb 1, 2015 6:27 PM, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
<br>
</span><span class="">> > In other words, the similarity between slices and ranges is not as close<br>
> > as you think.<br>
><br>
> Fair enough.  But it doesn't really affect my proposal.  It would just be<br>
> that this syntax only allows a subset of what you can do with slices.<br>
<br>
</span>It undercuts the justification for the proposal. Greg has also shown<br>
that even with purely integer values, slices and ranges behave differently.<br>
<br>
Slice objects are not a special case of ranges, and ranges are not a<br>
special case of slice objects. They behave differently, have different<br>
restrictions on their parameters, and different purposes. As far as I<br>
can see, virtually the only similarity is the names of the three<br>
parameters: start, stop, step.<br>
<br>
You might object that there is an important similarity that I've missed:<br>
slices (well, some slices) provide the same integer indexes as range<br>
does. That is, for at least *some* combinations of integers a, b and c,<br>
we have this invariant:<br>
<br>
seq[a:b:c] == [seq[i] for i in range(a, b, c)]<br>
<br>
But that's not a property of the slice object, that's a property of the<br>
sequence! Slice object merely record the start, stop, step, which can be<br>
arbitrary values in arbitrary order, and the sequence decides how to<br>
interpret it.<br>
<br>
The docs carefully don't describe the meaning of a slice object except<br>
as a bundle of start, stop, step attributes:<br>
<br>
<a href="https://docs.python.org/3/library/functions.html#slice" target="_blank">https://docs.python.org/3/library/functions.html#slice</a><br>
<br>
That's because slice objects don't have any meaning except that which<br>
the sequence chooses to give it. That is not true for range objects.<br>
<br>
(By the way, the docs are wrong when they say slice objects have no<br>
other explicit functionality: they also have an indices method.)<br>
<br>
The above invariant is the conventional meaning, of course, and I'm not<br>
suggesting that there are a lot of classes that ignore that conventional<br>
meaning and do something else. But slice objects exist to be a simple<br>
bundle of three attributes with arbitrary values, and ranges exist to be<br>
a linear iterable of integers. The fact that sometimes they appear to<br>
kind of almost overlap in meaning is incidental.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>Then let's ignore the original justification, and say this is just a syntax for making ranges that is similar to, but not identical to, slices.<br></div></div></div></div>