I think that represent-the-previous-expression is very nice syntactically. But how would it work internally?
/ Mirar
Previous text:
2003-05-15 22:23: Subject: Negative ranges revisited
I don't have any obvious operator to propose (ideally, it should be something that can be associated with the end of the string), but for the syntax, you just add it before the index, either after the leading [ or after the ... (One could also have it before the .., if one likes that symmetry better).
As for negation, there are two choices. I think I'd prefer to say that 0 is the position after the end of the string, -1 the position before that, and so on. Say we make the random choise of % for the magic character (any binary operator could be reused, as could for example:, ;, ,, /, @, $).
Then "banan"[%-3..%-1] == "nan", "banan"[%-4..4] == "ana". The easiest way to understand it is to think of %, in this context, as a shorthand for "sizeof(the string or array in question) +".
Actually, $ might be a better choice than %, anyone familiar with regexps can easily associate it to "end". Then it's
"banan"[$-3..$-1]
And when talking about ranges, I still like the old idea of using (x..y), [x..y) etc to represent open and half open intervals ;-)
/ Niels Möller (med röd bil)