Strings and arrays would be the same in this respect. Perhaps something like
prefix(string|array x, 17) // first 17 elements prefix(string|array x, -17) // all but the last 17 elements
suffix(string|array x, -17) // last 17 suffix(string|array x, 17) // all but the first 17
would be nice and clean? The number indicates a *position* in the string, where 0..length counts from the start of the string, and -length..-1 counts from the end. prefix returns the part of the string before this position, suffix the part efter the position.
Or one could reverse the role of the sign in the suffix function, if that's more intuitive, although at the moment I think
s == prefix(s, k) + suffix(s, k)
is nicer than
s == prefix(s, k) + suffix(s, -k)
Anyway, one should think carefully about off-by-one issues when designing this, from the last time we discussed it I think it was clear at least to me that the interpretation of negative numbers in ordinary indexing was sligthly wrong (sorry, I don't quite remeber the details), so one may have to choose between doing the right thing, or staying compatible with other indexing operations.
/ Niels Möller ()
Previous text:
2003-03-05 23:25: Subject: Re: negative indices in array ranges
but those are for strings, this is about arrays.
greetings, martin.
/ Brevbäraren