Looping over 1:length(a)
is wrong for AbstractVector
because it fails for non 1-based arrays. eachindex(a)
is correct, but occasionally you need to provide explicit indices, e.g. to loop only over odd indices as in #23267. start(a):endof(a)
doesn't work because for views start(a)
is a tuple. You can do first(eachindex(a))
, but this is kind of klunky and non-obvious.
Can we export a function startof
beginof(a) = first(eachindex(a))
analogous to endof(a)
?
Since the consensus in #15750 was for a begin
keyword for getindex
expressions, similar to end
, then the corresponding function should be beginof
.
startof
reads nicer than beginof
, if this is open for naming comments...
@ararslan, startof
was my initial thought as well, but if we implement a[begin:end]
syntactic sugar (as seems to be the clear consensus), then I feel like it pretty much has to translate to beginof
in analogy to endof
.
We can implement the function before we implement any syntactic sugar for it, but we should still name it consistently with the planned sugar.
What about changing both to begin_index
and end_index
?
Or beginindex
and endindex
Most helpful comment
Or
beginindex
andendindex