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

foldr(-,2:2) throws an error while foldl(-,2:2) does not #21107

Closed
dlfivefifty opened this issue Mar 20, 2017 · 2 comments
Closed

foldr(-,2:2) throws an error while foldl(-,2:2) does not #21107

dlfivefifty opened this issue Mar 20, 2017 · 2 comments

Comments

@dlfivefifty
Copy link
Contributor

I assume this change was intentional:

julia> foldr(-,2:2)  # 0.5
2
julia> foldr(-,2:2) # 0.6
ERROR: BoundsError: attempt to access 1-element UnitRange{Int64} at index [0]
Stacktrace:
 [1] throw_boundserror(::UnitRange{Int64}, ::Int64) at ./abstractarray.jl:426
 [2] getindex at ./range.jl:464 [inlined]
 [3] mapfoldr_impl(::Base.#identity, ::Base.#-, ::Int64, ::UnitRange{Int64}, ::Int64) at ./reduce.jl:110
 [4] mapfoldr(::Base.#identity, ::Function, ::UnitRange{Int64}) at ./reduce.jl:139
 [5] foldr(::Function, ::UnitRange{Int64}) at ./reduce.jl:166

The reason behind this change makes sense, but the error message was confusing.

@dlfivefifty
Copy link
Contributor Author

dlfivefifty commented Mar 20, 2017

Actually, I think it's a bug:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0-pre.alpha.193 (2017-03-20 02:33 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 28ea9d4 (0 days old master)
|__/                   |  x86_64-apple-darwin16.4.0

julia> reduce(-,2:2)
2

julia> foldl(-,2:2)
2

julia> foldr(-,2:2)
ERROR: BoundsError: attempt to access 1-element UnitRange{Int64} at index [0]
Stacktrace:
 [1] throw_boundserror(::UnitRange{Int64}, ::Int64) at ./abstractarray.jl:426
 [2] getindex at ./range.jl:464 [inlined]
 [3] mapfoldr_impl(::Base.#identity, ::Base.#-, ::Int64, ::UnitRange{Int64}, ::Int64) at ./reduce.jl:110
 [4] mapfoldr(::Base.#identity, ::Function, ::UnitRange{Int64}) at ./reduce.jl:139
 [5] foldr(::Function, ::UnitRange{Int64}) at ./reduce.jl:166

@dlfivefifty dlfivefifty changed the title foldr(-,2:2) could have better error message foldr(-,2:2) throws an error while foldl(-,2:2) does not Mar 20, 2017
@dlfivefifty
Copy link
Contributor Author

Note this is related to #20144

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

1 participant