[Python-ideas] Where did we go wrong with negative stride?

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Oct 30 22:44:45 CET 2013


Nick Coghlan wrote:

> That means that until people have fully explored exactly the semantics
> they want in terms of the existing object model ... then there are *zero*
 > grounds to be discussing syntax changes that provide those new semantics.

I don't think it's possible to decouple the syntactic and
semantic issues that easily.

Consider the problem of how to specify from-the-end indexes
without zero behaving incorrectly. There are a couple of
ways this could be tackled.

One would be to introduce a new type representing an
index from the end. This wouldn't require any new syntax,
but it would be verbose to spell out, so later we would
probably want to consider a new syntax for constructing
this type inside a slice expression.

But if we're willing to consider new syntax, we don't
need a new type -- we can just invent a syntax for
specifying from-the-end indexing directly, and end
up with a simpler design overall.

There would obviously have to be some way of specifying
the same thing that the new syntax specifies using
arguments to slice(), but that would be mostly an
implementation detail. It shouldn't be the driving
force behind the design.

-- 
Greg


More information about the Python-ideas mailing list