(I've been musing about similar things recently when writing the
getindex function for a ragged array datatype, where 'end' means a
different number depending on the column. However, that is a slightly
different but related matter:
https://groups.google.com/d/msg/julia-users/a5T9CoHLqeA/qfKg2jZje9UJ)
More generally, I think it would be nice to have some kind of slice
object like python does. It could be just a range in simple cases but
something more complicated when an 'end' features. Then one could build
up slices without an array and pass them around.
sli = colon(start, step, end)
and it should be possible to specify the 'end' in terms of just a number
or in terms of end minus number. E.g.:
sli = colon(5, 7, end-5)
a[sli] # equivalent to a[5:7:end-5]
b[sli] # equivalent to b[5:7:end-5]
Maybe 'end' could be a type and 'colon' featuring and 'end' would
produce a special range (otherwise just a normal range). Then getindex
could figure out what 'end' is when called for a specific indexable
collection.
(Then in Spencer's example it would have to be slightly more verbosely
s = 1:end)
In fact, the de-sugaring of 'end' in indices to size(a,n) seems a bit
in-transparent. Could something like above maybe rectify this?
(But probably a lot of work and not urgent.)