Yes, but these only work for calculating indices within []
; many times you might wish to calculate indices outside, such as in the OP. Hence, the motivation for EndyIndexes.jl, this suggestion for $begin
and $end
, and EndpointRanges.jl. (Not to mention, the motivation for the @view
macro, @jishnub’s OrdinalIndexing.jl, and this thread.) The suggestion to do arithmetic with first
and last
is just to use existing singleton objects, instead of introducing new start_
and end_
or ibegin
and iend
objects.
Additionally, because first+x
and last-y
could return special from-start and from-end indexing objects, they could be used for efficiently indexing strings by character (instead of by byte). For example, I’d imagine "αβγ"[first+1:last-1]
would return "β"
(with getindex
making appropriate calls to nextind
and prevind
under the hood).