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

change for i in 1:length(a) to i in eachindex(a) (continuing #10858) #12788

Closed
wants to merge 1 commit into from

Conversation

stevengj
Copy link
Member

Continuing the changes made in #10858 and #8432, this changes for i = 1:length(a) to for i in eachindex(a) throughout Base, and adds missing eachindex methods for Number and Tuple types (which are required for generic code).

There should be no performance penalty to this, since in most cases eachindex(a) inlines to 1:length(a) anyway. But since using eachindex(a) in loops is now the preferred style, it seemed best to do it consistently in Base, both to establish the habit and to catch any problems.

@stevengj
Copy link
Member Author

This is not quite right yet because of the issues mentioned by @timholy in #10858. But we should really have tests for those issues, and I wanted to see what would happen...

@@ -10,6 +10,7 @@ eltype{T<:Number}(::Type{T}) = T
ndims(x::Number) = 0
ndims{T<:Number}(::Type{T}) = 0
length(x::Number) = 1
eachindex(x::Number) = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( cant wait for that to go away

@stevengj
Copy link
Member Author

Closing as this seems more trouble than it is worth.

@timholy
Copy link
Sponsor Member

timholy commented Sep 18, 2015

Obviously, it will be good to have something like this return in 0.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants