-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Description
And similarly for setindex!
.
For example:
type A end
Base.getindex(a::A, ::Range) = 0
Base.getindex(a::A, ::Colon) = 1
julia> A()[:]
ERROR: `endof` has no method matching endof(::A)
This is worse if endof(::A)
is defined, as then A()[:]
chooses silently the unintended getindex
method.
If allowing customization of Base.getindex(a::A, ::Colon)
does not happen, I would request that a[:]
is translated to a[beginof(a):endof(a)]
, as some indexable collections have an indice starting at something else than 1.
At the very least, the doc for getindex/setindex!
should mention this special case, where "The syntax a[i,j,...]
is converted by the compiler to getindex(a, i, j, ...)
" does not seem true.
Also, in "base/subarray.jl", this method is defined: getindex{T}(v::AbstractArray{T,1}, ::Colon) = v
, should it be removed or is it used?
Metadata
Metadata
Assignees
Labels
No labels