Discussion
1. Should slices have special syntax?
We could potentially use the bit-slice syntax to pull out parts of an array. However, since they don't really match up we have some freedom to decide whether we have <lower index>:<high index inclusive>, <lower index>:<high index exclusive>, <lower index>:<size>
Since arrays are used as first class objects, it makes sense that creating slices of arrays similarly has special syntax.
int[] a = { 1, 2, 3, 4, 5, 6 };
int[] b = a[2:3]; // { 3, 4 }, { 3 } or { 3, 4, 5 } depending on definition.
Note that a slice does not outlive the lifetime of an array.
2. Negative indexing
It is possible to use negative indices as shorthand for length - index. So a[-1] is the same as a[a.length - 1]. It's very convenient but means extra instructions. Basically it means unpacking any a to a.start + (i < 0 ? a.length - i : i). Expensive!
3. Extending array methods
Since arrays are generic-ish, we'd need some more generic way of expressing function on it. But it would be useful. The aforementioned negative indexing could be implemented as a function:
func any[].slice(any[] array, i64 index, i64 length) {
index = index < 0 ? index + array.length;
length = length < 0 ? length + array.length;
return array[index:length];
}
(In general, considering generic functions is important!)
4. Growable arrays
This is a topic on its own. But let's just mention that it needs some kind of memory management and as such we should consider memory management a bit in detail (in another topic)