Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beginof(a) analogue to endof(a)? #23354

Closed
stevengj opened this issue Aug 19, 2017 · 6 comments
Closed

beginof(a) analogue to endof(a)? #23354

stevengj opened this issue Aug 19, 2017 · 6 comments
Labels
arrays [a, r, r, a, y, s]

Comments

@stevengj
Copy link
Member

stevengj commented Aug 19, 2017

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)?

@stevengj stevengj added the arrays [a, r, r, a, y, s] label Aug 19, 2017
@yuyichao
Copy link
Contributor

Re #15750

@stevengj stevengj changed the title startof(a) analogue to endof(a)? beginof(a) analogue to endof(a)? Aug 19, 2017
@stevengj
Copy link
Member Author

Since the consensus in #15750 was for a begin keyword for getindex expressions, similar to end, then the corresponding function should be beginof.

@ararslan
Copy link
Member

startof reads nicer than beginof, if this is open for naming comments...

@stevengj
Copy link
Member Author

@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.

@timholy
Copy link
Member

timholy commented Aug 20, 2017

What about changing both to begin_index and end_index?

@stevengj
Copy link
Member Author

Or beginindex and endindex

JeffBezanson added a commit that referenced this issue Jan 17, 2018
JeffBezanson added a commit that referenced this issue Jan 18, 2018
@Keno Keno closed this as completed in 742a539 Jan 26, 2018
Keno added a commit that referenced this issue Jan 26, 2018
Rename endof->lastindex and introduce firstindex. Fixes #23354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

4 participants