On 1 November 2013 13:26, אלעזר <elazarg@gmail.com> wrote:
2013/11/1 Oscar Benjamin <oscar.j.benjamin@gmail.com>:
On 1 November 2013 10:17, Steven D'Aprano <steve@pearwood.info> wrote:
To break the ambiguity, we'd need a rule that End objects can only occur inside slices with at least one colon.
This would defeat much of the point of having a new notation. The problem with negative wraparound applies just as much to ordinary indexing as to slicing.
Not exactly as much. taking
x[:-0] # intention: x[:len(x)]
is a reasonable, which happens to fail in Python. While
x[-0] # intention: x[len(x)]
is an error in the first place, which happens not to raise an Exception in Python, but rather gives you a wrong result.
I'm not really sure what you mean by this so I'll clarify what I mean: If I write x[-n] then my intention is that n should always be positive. If n happens to be zero or negative then I really want an IndexError but I won't get one because it coincidentally has an alternate meaning. I would rather be able to spell that as x[end-n] and have any negative index be an error. While I can write x[len(x)-n] right now it still does the wrong thing when n>len(x). Oscar