Skip to content

Commit

Permalink
remove uses of A[n:] syntax from Base. ref #4678
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 27, 2013
1 parent 532f639 commit b4fa861
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function process_options(args::Array{Any,1})
color_set = true
global have_color = true
elseif args[i][8] == '='
val = args[i][9:]
val = args[i][9:end]
if in(val, ("no","0","false"))
color_set = true
global have_color = false
Expand Down
2 changes: 1 addition & 1 deletion base/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function reshape{T,S<:Array}(A::DArray{T,1,S}, d::Dims)

B = Array(T,sz)
nr = size(B,1)
sztail = size(B)[2:]
sztail = size(B)[2:end]

for i=1:div(length(B),nr)
i2 = ind2sub(sztail, i)
Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end
writedlm{T}(io::IO, a::AbstractArray{T,0}, dlm::Char) = writedlm(io, reshape(a,1), dlm)

function writedlm(io::IO, a::AbstractArray, dlm::Char)
tail = size(a)[3:]
tail = size(a)[3:end]
function print_slice(idxs...)
writedlm(io, sub(a, 1:size(a,1), 1:size(a,2), idxs...), dlm)
if idxs != tail
Expand Down
14 changes: 7 additions & 7 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ function abstract_call(f, fargs, argtypes, vtypes, sv::StaticVarInfo, e)
af = isconstantfunc(fargs[1], sv)
end
if !is(af,false)
aargtypes = argtypes[2:]
aargtypes = argtypes[2:end]
if all(x->isa(x,Tuple), aargtypes) &&
!any(isvatuple, aargtypes[1:(length(aargtypes)-1)])
e.head = :call1
Expand Down Expand Up @@ -704,7 +704,7 @@ function abstract_call(f, fargs, argtypes, vtypes, sv::StaticVarInfo, e)
sig = argtypes[2]
if isa(sig,Tuple) && all(isType, sig)
sig = map(t->t.parameters[1], sig)
return invoke_tfunc(af, sig, argtypes[3:])
return invoke_tfunc(af, sig, argtypes[3:end])
end
end
end
Expand Down Expand Up @@ -751,7 +751,7 @@ function abstract_eval_arg(a::ANY, vtypes::ANY, sv::StaticVarInfo)
end

function abstract_eval_call(e, vtypes, sv::StaticVarInfo)
fargs = e.args[2:]
fargs = e.args[2:end]
argtypes = tuple([abstract_eval_arg(a, vtypes, sv) for a in fargs]...)
if any(x->is(x,None), argtypes)
return None
Expand Down Expand Up @@ -1204,7 +1204,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
end
s[1][args[la]] = Tuple
else
s[1][args[la]] = limit_tuple_depth(atypes[la:])
s[1][args[la]] = limit_tuple_depth(atypes[la:end])
end
la -= 1
else
Expand Down Expand Up @@ -1483,7 +1483,7 @@ function eval_annotate(e::ANY, vtypes::ANY, sv::StaticVarInfo, decls, clo)
end
if (head === :call || head === :call1) && isa(e.args[1],LambdaStaticData)
called = e.args[1]
fargs = e.args[2:]
fargs = e.args[2:end]
argtypes = tuple([abstract_eval_arg(a, vtypes, sv) for a in fargs]...)
# recur inside inner functions once we have all types
tr,ty = typeinf(called, argtypes, called.sparams, called, false)
Expand Down Expand Up @@ -1725,7 +1725,7 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
if !(isa(f,Function) || isstructtype(f) || isa(f,IntrinsicFunction))
return NF
end
argexprs = e.args[2:]
argexprs = e.args[2:end]
atypes = tuple(map(exprtype, argexprs)...)
if length(atypes) > MAX_TUPLETYPE_LEN
atypes = limit_tuple_type(atypes)
Expand Down Expand Up @@ -2039,7 +2039,7 @@ function inlining_pass(e::Expr, sv, ast)
t = exprtype(aarg)
if isa(aarg,Expr) && is_known_call(aarg, tuple, sv)
# apply(f,tuple(x,y,...)) => f(x,y,...)
newargs[i-2] = aarg.args[2:]
newargs[i-2] = aarg.args[2:end]
elseif isa(t,Tuple) && !isvatuple(t) && effect_free(aarg,sv)
# apply(f,t::(x,y)) => f(t[1],t[2])
newargs[i-2] = { mk_tupleref(aarg,j) for j=1:length(t) }
Expand Down
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function write{T,N,A<:Array}(s::IOStream, a::SubArray{T,N,A})
return write(s, pointer(a, 1), colsz)
else
cartesianmap((idxs...)->write(s, pointer(a, idxs), colsz),
tuple(1, size(a)[2:]...))
tuple(1, size(a)[2:end]...))
return colsz*trailingsize(a,2)
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function null{T<:BlasFloat}(A::StridedMatrix{T})
(m == 0 || n == 0) && return eye(T, n)
SVD = svdfact(A, false)
indstart = sum(SVD[:S] .> max(m,n)*maximum(SVD[:S])*eps(eltype(SVD[:S]))) + 1
return SVD[:V][:,indstart:]
return SVD[:V][:,indstart:end]
end
null{T<:Integer}(A::StridedMatrix{T}) = null(float(A))
null(a::StridedVector) = null(reshape(a, length(a), 1))
Expand Down
2 changes: 1 addition & 1 deletion base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ macro parallel(args...)
ex = loop.args[1]
loop.args[1] = esc(ex)
nd = length(loop.args)-1
ranges = map(e->esc(e.args[2]), loop.args[2:])
ranges = map(e->esc(e.args[2]), loop.args[2:end])
for i=1:nd
var = loop.args[1+i].args[1]
loop.args[1+i] = :( $(esc(var)) = ($(ranges[i]))[I[$i]] )
Expand Down
6 changes: 3 additions & 3 deletions base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function _parse(s::String)
j = k
end
end
isempty(s[i:]) || push!(list, s[i:])
isempty(s[i:end]) || push!(list, s[i:end])
# coalesce adjacent strings
i = 1
while i < length(list)
Expand Down Expand Up @@ -774,11 +774,11 @@ macro printf(args...)
if isa(args[1],String)
io = :(Base.STDOUT)
fmt = args[1]
args = args[2:]
args = args[2:end]
else
io = args[1]
fmt = args[2]
args = args[3:]
args = args[3:end]
end
args = {io,args...}
sym_args, blk = _gen(fmt)
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ function show_nd(io::IO, a::AbstractArray, limit, rows, cols)
if isempty(a)
return
end
tail = size(a)[3:]
tail = size(a)[3:end]
nd = ndims(a)-2
function print_slice(idxs...)
if limit
Expand Down
6 changes: 3 additions & 3 deletions base/sparse/csparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,18 @@ end

etree(A::SparseMatrixCSC) = etree(A, false)

# find nonzero pattern of Cholesky L(k,1:k-1) using etree and triu(A(:,k))
# find nonzero pattern of Cholesky L[k,1:k-1] using etree and triu(A[:,k])
# based on cs_ereach p. 43, "Direct Methods for Sparse Linear Systems"
function ereach{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, k::Integer, parent::Vector{Ti})
m,n = size(A); Ap = A.colptr; Ai = A.rowval
s = Ti[]; sizehint(s, n) # to be used as a stack
visited = falses(n)
visited[k] = true
for p in Ap[k]:(Ap[k+1] - 1)
i = Ai[p] # A(i,k) is nonzero
i = Ai[p] # A[i,k] is nonzero
if i > k continue end # only use upper triangular part of A
while !visited[i] # traverse up etree
push!(s,i) # L(k,i) is nonzero
push!(s,i) # L[k,i] is nonzero
visited[i] = true
i = parent[i]
end
Expand Down
4 changes: 2 additions & 2 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ function shell_parse(raw::String, interp::Bool)
if in_single_quotes; error("unterminated single quote"); end
if in_double_quotes; error("unterminated double quote"); end

update_arg(s[i:])
update_arg(s[i:end])
append_arg()

if !interp
Expand Down Expand Up @@ -1275,7 +1275,7 @@ function split(str::String, splitter, limit::Integer, keep_empty::Bool)
j, k = first(r), nextind(str,last(r))
end
if keep_empty || !done(str,i)
push!(strs, str[i:])
push!(strs, str[i:end])
end
return strs
end
Expand Down
4 changes: 2 additions & 2 deletions base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ end
# the parent array
function translate_linear_indexes(s, n, I, pdims)
idx = Array(Int, length(I))
ssztail = size(s)[n:]
indexestail = s.indexes[pdims[n:]]
ssztail = size(s)[n:end]
indexestail = s.indexes[pdims[n:end]]
# The next gets the strides of dimensions listed in pdims[n:end], relative to the stride of pdims[n]
pstrd = [1]
j = n+1
Expand Down
4 changes: 2 additions & 2 deletions base/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ function string(a::ByteString...)
UTF8String(data)
end

ucfirst(s::UTF8String) = string(uppercase(s[1]), s[2:])
lcfirst(s::UTF8String) = string(lowercase(s[1]), s[2:])
ucfirst(s::UTF8String) = string(uppercase(s[1]), s[2:end])
lcfirst(s::UTF8String) = string(lowercase(s[1]), s[2:end])

function reverse(s::UTF8String)
out = similar(s.data)
Expand Down

5 comments on commit b4fa861

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

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

Wait, I thought the upshot of #4678 was that we don't need to remove the a[2:] syntax, just make the :2 syntax illegal and arrange to print an error indicating that they should use 1:2 instead.

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

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

I find that unsatisfying --- if a type actually does support indexing with symbols, then a[:n] vs. a[n:] is confusing again.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

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

n: isn't a syntax for a symbol so I'm not sure how that's relevant.

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

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

a[:n] indexes with a symbol and a[n:] indexes from n to the end, so the same kind of asymmetry is still there. It would be weird for a type to support both of these, but you could get an expression like a[:n] + b[m:] that is kind of misleading.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

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

I guess. So we're going with the only colon form that allows implied end-points being the bare : where both are implied?

Please sign in to comment.