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

1:3 != collect(1:3) #13565

Closed
nalimilan opened this issue Oct 12, 2015 · 3 comments
Closed

1:3 != collect(1:3) #13565

nalimilan opened this issue Oct 12, 2015 · 3 comments

Comments

@nalimilan
Copy link
Member

Is the fact that 1:3 != collect(1:3) intended? I can see in the definition of == that comparisons between Range and Array are explicitly handled to return false, but I can't find a good reason for that.

julia> x = 1:3
1:3

julia> y = collect(x)
3-element Array{Int64,1}:
 1
 2
 3

julia> x == y
false

# And yet:
julia> all(Bool[i == j for (i, j) in zip(x, y)])
true

help?> ==
[...]
  Collections should generally implement == by calling == recursively on all
  contents.
[...]
@simonster
Copy link
Member

Yes, ranges are not equal to non-ranges because otherwise hashing a range would require hashing every element, which could take quite a while.

@simonster
Copy link
Member

See also #5778 (comment), #6084, #12226

@nalimilan
Copy link
Member Author

Ah, thanks, not sure how I forgot these discussions. Looks like the two most recent comments at #12226 (comment) point to a possible solution.

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

No branches or pull requests

2 participants