<p dir="ltr"><br>
On Feb 1, 2015 6:27 PM, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
><br>
> On Sun, Feb 01, 2015 at 04:13:32PM +0100, Todd wrote:<br>
> > Although slices and ranges are used for different things and implemented<br>
> > differently, conceptually they are similar: they define an integer sequence<br>
> > with a start, stop, and step size.<br>
><br>
> I'm afraid that you are mistaken. Slices do not necessarily define<br>
> integer sequences. They are completely arbitrary, and it is up to the<br>
> object being sliced to interpret what is or isn't valid and what the<br>
> slice means.<br>
><br>
> py> class K(object):<br>
> ... def __getitem__(self, i):<br>
> ... print(i)<br>
> ...<br>
> py> K()["abc":(2,3,4):{}]<br>
> slice('abc', (2, 3, 4), {})<br>
><br>
><br>
> In addition, the "stop" argument to a slice may be unspecified until<br>
> it it applied to a specific sequence, while range always requires<br>
> stop to be defined.<br>
><br>
> py> s = slice(1, None, 2)<br>
> py> "abcde"[s]<br>
> 'bd'<br>
> py> "abcdefghi"[s]<br>
> 'bdfh'<br>
><br>
> It isn't meaningful to define a range with an unspecified stop, but it<br>
> is meaningful to do so for slices.<br>
><br>
><br>
> In other words, the similarity between slices and ranges is not as close<br>
> as you think.<br>
></p>
<p dir="ltr">Fair enough. But it doesn't really affect my proposal. It would just be that this syntax only allows a subset of what you can do with slices. </p>