I got an idea of how to solve the age old issue of getting negative indices in ranges to work. We'd all like to do things like this:
foo = foo[..-2]; // Lose the last item.
But so far it hasn't worked because of cases like this:
foo = foo[..i-1] + foo[i+1..]; // Lose item i.
which should work even when i is zero.
My idea is to give the unary negation operator an additional literal meaning in the range operator. I.e. in the expression
foo[-a..-b]
both index operations takes place in the range -sizeof(foo)..-1 instead of the normal 0..sizeof(foo)-1. The expressions a and b are negated as usual. Thus, if they already contain the negative indices a double negation would be necessary:
foo[..- -b]
That's easily optimized away. Another example:
// Lose item i, where i is in the range -sizeof(foo)..-1. foo = foo[..- -(i-1)] + foo[- -(i+1)..];
There's a compatibility issue here, but I think it's minor. Only cases where range expressions are negated are affected. That means expressions that evaluate to values in the range 0 for the first element down to -sizeof(foo)+1 for the last, which I believe is fairly odd.
How to convey this to the range lfuns remains to be solved.
What do you say? Would it be too strange?