I am looking at the documentation about slicing and was wondering if its possible to only specify step. In Python this is possible using the double colon:
This ended up being more subtle than I thought but I believe this works:
array[] int range(int start, int stop, int step) {
if (start > stop) {
int n = (start - stop) %/% -step;
int begin = n * step + start;
return reverse(linspaced_int_array(n + 1, begin, start));
}
int n = (stop - start) %/% step;
int end = n * step + start;
return linspaced_int_array(n + 1, start, end);
}
Note that the result is inclusive on both ends, such that range(0,10,2) == {0, 2, 4, 6, 8, 10}