I like this idea and think it fits well with Arc's theme of compactness.
What are all the possible implications? For example, it could be implemented as an isolated feature, but having negative indexes start from the right kinda makes me crave a '-car and '-cdr that start from the right as well. Additionally, if you're going to wrap around at the zero index, does it make sense to wrap around at all indices where mod length equals zero? That is, does
(let xs '(a b c)
(and (is xs.0 xs.3)
(is xs.1 xs.4)
(is xs.2 xs.5)) ; etc.
evaluate to true? This would be kind of a serious change and probably not very useful, IMO. (To be sure, I'm not really suggesting that these follow from your idea per se but rather from taking its characteristics to extremes.)
Finally, just a ssyntax question: would
xs.-1
work? I think it certainly should if negative indexing were implemented, just wondering if our underlying machinery might have trouble correctly parsing the dot and hyphen together.
To model indexing after Python, valid indices for a sequence of length n would be integers in the range [-n, n).
>>> xs = ['a', 'b', 'c']
>>> xs[0] is xs[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> xs[0] is xs[-6]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> xs[0] is xs[-3]
True
Hence "To model indexing after Python". I figure Python's probably a good source of inspiration for Python-like features. ;)
Admittedly, I can't find specific rationale for IndexErrors discussed anywhere. Perhaps throwing errors for egregious indices just seems the "sane" thing to do. Essentially, it's a choice of foist: if indexing wraps around infinitely, you need to check bounds when you don't want to wrap around; if indexing throws errors, you need to mod explicitly when you do want to wrap around.
> if indexing wraps around infinitely, you need to check bounds when you don't want to wrap around; if indexing throws errors, you need to mod explicitly when you do want to wrap around.
Good summary. I agree that index-out-of-bound errors are the saner default.