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

Deprecate no space between expression and ? in ternaries #22523

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function exprresolve(ex::Expr)
if ex.head == :if
can_eval, tf = exprresolve_conditional(ex.args[1])
if can_eval
ex = tf?ex.args[2]:ex.args[3]
ex = tf ? ex.args[2] : ex.args[3]
end
end
ex
Expand Down
4 changes: 2 additions & 2 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ avgdistance(xs) =
function fuzzyscore(needle, haystack)
score = 0.
is, acro = bestmatch(needle, haystack)
score += (acro?2:1)*length(is) # Matched characters
score += (acro ? 2 : 1)*length(is) # Matched characters
score -= 2(length(needle)-length(is)) # Missing characters
!acro && (score -= avgdistance(is)/10) # Contiguous
!isempty(is) && (score -= mean(is)/100) # Closer to beginning
Expand Down Expand Up @@ -330,7 +330,7 @@ function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = displays
total = 0
for i = 1:length(ss)
total += length(ss[i])
total + max(i-2,0)*length(delim) + (i>1?1:0)*length(last) > cols && (i-=1; break)
total + max(i-2,0)*length(delim) + (i>1 ? 1 : 0)*length(last) > cols && (i-=1; break)
end
join(io, ss[1:i], delim, last)
end
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ include("path.jl")
include("stat.jl")
include("file.jl")
include("poll.jl")
include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)

## Operations with File (fd) objects ##

Expand Down
2 changes: 1 addition & 1 deletion base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if is_windows()
export GetLastError, FormatMessage
end

include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)

## RawFD ##

Expand Down
4 changes: 2 additions & 2 deletions base/libgit2/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

function message(c::GitCommit, raw::Bool=false)
local msg_ptr::Cstring
msg_ptr = raw? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Void},), c.ptr) :
ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Void},), c.ptr)
msg_ptr = raw ? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Void},), c.ptr) :
ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Void},), c.ptr)
if msg_ptr == C_NULL
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Core definitions for interacting with the libuv library from Julia

include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)

# convert UV handle data to julia object, checking for null
function uv_sizeof_handle(handle)
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ julia> Bidiagonal(A, false) #contains the main diagonal and first subdiagonal of
⋅ ⋅ 4 4
```
"""
Bidiagonal(A::AbstractMatrix, isupper::Bool)=Bidiagonal(diag(A), diag(A, isupper?1:-1), isupper)
Bidiagonal(A::AbstractMatrix, isupper::Bool)=Bidiagonal(diag(A), diag(A, isupper ? 1 : -1), isupper)

function getindex(A::Bidiagonal{T}, i::Integer, j::Integer) where T
if !((1 <= i <= size(A,2)) && (1 <= j <= size(A,2)))
Expand Down Expand Up @@ -241,7 +241,7 @@ function show(io::IO, M::Bidiagonal)
println(io, summary(M), ":")
print(io, " diag:")
print_matrix(io, (M.dv)')
print(io, M.isupper?"\n super:":"\n sub:")
print(io, M.isupper ? "\n super:" : "\n sub:")
print_matrix(io, (M.ev)')
end

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ for (gels, gesv, getrs, getri, elty) in
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
&(btrn?'T':'N'), &m, &n, &size(B,2), A, &max(1,stride(A,2)),
&(btrn ? 'T' : 'N'), &m, &n, &size(B,2), A, &max(1,stride(A,2)),
B, &max(1,stride(B,2)), work, &lwork, info)
chklapackerror(info[])
if i == 1
Expand Down
8 changes: 4 additions & 4 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ end
function copy!(A::T, B::T) where T<:Union{UpperTriangular,UnitUpperTriangular}
n = size(B,1)
for j = 1:n
for i = 1:(isa(B, UnitUpperTriangular)?j-1:j)
for i = 1:(isa(B, UnitUpperTriangular) ? j-1 : j)
@inbounds A[i,j] = B[i,j]
end
end
Expand All @@ -381,7 +381,7 @@ end
function copy!(A::T, B::T) where T<:Union{LowerTriangular,UnitLowerTriangular}
n = size(B,1)
for j = 1:n
for i = (isa(B, UnitLowerTriangular)?j+1:j):n
for i = (isa(B, UnitLowerTriangular) ? j+1 : j):n
@inbounds A[i,j] = B[i,j]
end
end
Expand All @@ -394,7 +394,7 @@ function scale!(A::UpperTriangular, B::Union{UpperTriangular,UnitUpperTriangular
if isa(B, UnitUpperTriangular)
@inbounds A[j,j] = c
end
for i = 1:(isa(B, UnitUpperTriangular)?j-1:j)
for i = 1:(isa(B, UnitUpperTriangular) ? j-1 : j)
@inbounds A[i,j] = c * B[i,j]
end
end
Expand All @@ -406,7 +406,7 @@ function scale!(A::LowerTriangular, B::Union{LowerTriangular,UnitLowerTriangular
if isa(B, UnitLowerTriangular)
@inbounds A[j,j] = c
end
for i = (isa(B, UnitLowerTriangular)?j+1:j):n
for i = (isa(B, UnitLowerTriangular) ? j+1 : j):n
@inbounds A[i,j] = c * B[i,j]
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module PCRE

include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","pcre_h.jl")) # include($BUILDROOT/base/pcre_h.jl)
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "pcre_h.jl")) # include($BUILDROOT/base/pcre_h.jl)

const PCRE_LIB = "libpcre2-8"

Expand Down
24 changes: 12 additions & 12 deletions base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ function gen_d(flags::String, width::Int, precision::Int, c::Char)
push!(blk.args, pad(width-precision, padding, ' '))
end
# print sign
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
push!(blk.args, :(neg && write(out, '-')))
# print prefix
for ch in prefix
Expand Down Expand Up @@ -362,8 +362,8 @@ function gen_f(flags::String, width::Int, precision::Int, c::Char)
push!(blk.args, pad(width-1, padding, ' '))
end
# print sign
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
push!(blk.args, :(neg && write(out, '-')))
# print zero padding
if padding !== nothing && !('-' in flags) && '0' in flags
Expand Down Expand Up @@ -456,8 +456,8 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo
push!(blk.args, pad(width, padding, ' '))
end
# print sign
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
push!(blk.args, :(neg && write(out, '-')))
# print zero padding
if padding !== nothing && !('-' in flags) && '0' in flags
Expand Down Expand Up @@ -554,16 +554,16 @@ function gen_a(flags::String, width::Int, precision::Int, c::Char)
if '#' in flags
padding = :($padding - (len-1))
else
padding = :($padding - (len>1?len:0))
padding = :($padding - (len>1 ? len : 0))
end
end
# print space padding
if padding !== nothing && !('-' in flags) && !('0' in flags)
push!(blk.args, pad(width, padding, ' '))
end
# print sign
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
push!(blk.args, :(neg && write(out, '-')))
# hex prefix
for ch in hexmark
Expand Down Expand Up @@ -630,7 +630,7 @@ function _limit(s, prec)
prec >= sizeof(s) && return s
p = prevind(s, prec+1)
n = nextind(s, p)-1
s[1:(prec>=n?n:prevind(s,p))]
s[1:(prec>=n ? n : prevind(s,p))]
end

function gen_s(flags::String, width::Int, precision::Int, c::Char)
Expand Down Expand Up @@ -755,8 +755,8 @@ function gen_g(flags::String, width::Int, precision::Int, c::Char)
$padexpr; end))
end
# print sign
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
push!(blk.args, :(neg && write(out, '-')))
# print zero padding
if !('-' in flags) && '0' in flags
Expand Down
4 changes: 2 additions & 2 deletions base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))))

function _rand_pm1!(v)
for i in eachindex(v)
v[i] = rand()<0.5?1:-1
v[i] = rand()<0.5 ? 1 : -1
end
end

Expand Down Expand Up @@ -643,7 +643,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))))
S_old = copy(S)
for j = 1:t
for i = 1:n
S[i,j] = Y[i,j]==0?one(Y[i,j]):sign(Y[i,j])
S[i,j] = Y[i,j]==0 ? one(Y[i,j]) : sign(Y[i,j])
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,9 @@
(define (parse-cond s)
(let ((ex (parse-arrow s)))
(cond ((eq? (peek-token s) '?)
(begin (take-token s)
(begin (if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?")))
(take-token s)
(let ((then (without-range-colon (parse-eq* s))))
(if (not (eq? (take-token s) ':))
(error "colon expected in \"?\" expression")
Expand Down
2 changes: 1 addition & 1 deletion test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ end

# issue #4883
@test isa(broadcast(tuple, [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Int,String}})
@test isa(broadcast((x,y)->(x==1?1.0:x,y), [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Real,String}})
@test isa(broadcast((x,y)->(x==1 ? 1.0 : x, y), [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Real,String}})
let a = length.(["foo", "bar"])
@test isa(a, Vector{Int})
@test a == [3, 3]
Expand Down
4 changes: 2 additions & 2 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,9 @@ function testmap_equivalence(f, c...)
end

testmap_equivalence(identity, (1,2,3,4))
testmap_equivalence(x->x>0?1.0:0.0, sparse(eye(5)))
testmap_equivalence(x->x>0 ? 1.0 : 0.0, sparse(eye(5)))
testmap_equivalence((x,y,z)->x+y+z, 1,2,3)
testmap_equivalence(x->x?false:true, BitArray(10,10))
testmap_equivalence(x->x ? false : true, BitArray(10,10))
testmap_equivalence(x->"foobar", BitArray(10,10))
testmap_equivalence((x,y,z)->string(x,y,z), BitArray(10), ones(10), "1234567890")

Expand Down
8 changes: 4 additions & 4 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ srand(1)
@testset "Constructor and basic properties" begin
@test size(T, 1) == size(T, 2) == n
@test size(T) == (n, n)
@test Array(T) == diagm(dv) + diagm(ev, isupper?1:-1)
@test Array(T) == diagm(dv) + diagm(ev, isupper ? 1 : -1)
@test Bidiagonal(Array(T), isupper) == T
@test big.(T) == T
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper ? 1 : -1))
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper ? 1 : -1))
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper ? 1 : -1))
end
z = zeros(elty, n)

Expand Down