by hackermom · 15y ago · 0 comments
Sure, it's a departure from mainstream languages, but in my opinion it's a perfectly sensible one.
Not necessarily. The reasoning in e.g. Python is that the index is not to an element, it's to one of the intervals around an element. The "first interval" (right before the first element) is 0, which naturally leads to -1 being right before the last element, thus arr[-1] being an array's last element, and arr[:-1] being everything but the last element.