Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c70d556

Browse files
davidavdavfcard
authored andcommittedFeb 28, 2017
Deprecate $ as bitwise xor, replace by xor(), as discussed in JuliaLang#18696 (JuliaLang#18977)
* Deprecate $ for xor() (JuliaLang#18696) This includes: - occurrances of $ (as infix operator) and $= in base - occurances of $ in test - the definition in the manual - the entry in REPL help This commit does not introduce an alternative, that will happen in the next commit. * Add ⊻ as alternative to xor, and `⊻=` as alternative to `$=`. Please note that `⊻=` is in the add-dots group in the parser, preparing for `.⊻=`. However, this commit does not implement `.⊻` yet, this should happen in a separate commit with `.&` and `.|` together. * Add deprecation comment in show.jl and deprecation item in NEWS.md
1 parent f107169 commit c70d556

39 files changed

+159
-134
lines changed
 

‎NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Deprecated or removed
6868

6969
* `num` and `den` have been deprecated in favor of `numerator` and `denominator` respectively ([#19233]).
7070

71+
* infix operator `$` has been deprecated in favor of infix `` or function `xor()` ([#18977]).
72+
7173
Julia v0.5.0 Release Notes
7274
==========================
7375

‎base/arraymath.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ promote_array_type{S<:Integer}(::typeof(./), ::Type{S}, ::Type{Bool}, T::Type) =
6666
promote_array_type{S<:Integer}(::typeof(.\), ::Type{S}, ::Type{Bool}, T::Type) = T
6767
promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T
6868

69-
for f in (:+, :-, :div, :mod, :&, :|, :$)
69+
for f in (:+, :-, :div, :mod, :&, :|, :xor)
7070
@eval ($f)(A::AbstractArray, B::AbstractArray) =
7171
_elementwise($f, promote_eltype_op($f, A, B), A, B)
7272
end
@@ -89,7 +89,7 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray)
8989
return F
9090
end
9191

92-
for f in (:.+, :.-, :.*, :./, :.\, :.^, :, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :$)
92+
for f in (:.+, :.-, :.*, :./, :.\, :.^, :, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :xor)
9393
@eval begin
9494
function ($f){T}(A::Number, B::AbstractArray{T})
9595
R = promote_op($f, typeof(A), T)

‎base/associative.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const hasha_seed = UInt === UInt64 ? 0x6d35bb51952d5539 : 0x952d5539
251251
function hash(a::Associative, h::UInt)
252252
h = hash(hasha_seed, h)
253253
for (k,v) in a
254-
h $= hash(k, hash(v))
254+
h = hash(k, hash(v))
255255
end
256256
return h
257257
end

‎base/bitarray.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,12 @@ function (|)(B::BitArray, x::Bool)
13331333
end
13341334
(|)(x::Bool, B::BitArray) = B | x
13351335

1336-
function ($)(B::BitArray, x::Bool)
1336+
function xor(B::BitArray, x::Bool)
13371337
x ? ~B : copy(B)
13381338
end
1339-
($)(x::Bool, B::BitArray) = B $ x
1339+
xor(x::Bool, B::BitArray) = xor(B, x)
13401340

1341-
for f in (:&, :|, :$)
1341+
for f in (:&, :|, :xor)
13421342
@eval begin
13431343
function ($f)(A::BitArray, B::BitArray)
13441344
F = BitArray(promote_shape(size(A),size(B))...)
@@ -2006,10 +2006,10 @@ map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A)
20062006

20072007
for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)),
20082008
(:(Union{typeof(|), typeof(max)}), :(|)),
2009-
(:(Union{typeof($), typeof(!=)}), :($)),
2009+
(:(Union{typeof(xor), typeof(!=)}), :xor),
20102010
(:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | ~q)),
20112011
(:(typeof(<=)), :((p, q) -> ~p | q)),
2012-
(:(typeof(==)), :((p, q) -> ~(p $ q))),
2012+
(:(typeof(==)), :((p, q) -> ~xor(p, q))),
20132013
(:(typeof(<)), :((p, q) -> ~p & q)),
20142014
(:(typeof(>)), :((p, q) -> p & ~q)))
20152015
@eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B)
@@ -2058,12 +2058,12 @@ transpose(B::BitVector) = reshape(copy(B), 1, length(B))
20582058
# http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt
20592059
function transpose8x8(x::UInt64)
20602060
y = x
2061-
t = (y $ (y >>> 7)) & 0x00aa00aa00aa00aa
2062-
y = y $ t $ (t << 7)
2063-
t = (y $ (y >>> 14)) & 0x0000cccc0000cccc
2064-
y = y $ t $ (t << 14)
2065-
t = (y $ (y >>> 28)) & 0x00000000f0f0f0f0
2066-
return y $ t $ (t << 28)
2061+
t = xor(y, y >>> 7) & 0x00aa00aa00aa00aa
2062+
y = xor(y, t, t << 7)
2063+
t = xor(y, y >>> 14) & 0x0000cccc0000cccc
2064+
y = xor(y, t, t << 14)
2065+
t = xor(y, y >>> 28) & 0x00000000f0f0f0f0
2066+
return xor(y, t, t << 28)
20672067
end
20682068

20692069
function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, cinc::Int, nc::Int, msk8::UInt64)

‎base/bool.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
(~)(x::Bool) = !x
2424
(&)(x::Bool, y::Bool) = box(Bool,and_int(unbox(Bool,x),unbox(Bool,y)))
2525
(|)(x::Bool, y::Bool) = box(Bool,or_int(unbox(Bool,x),unbox(Bool,y)))
26-
($)(x::Bool, y::Bool) = (x!=y)
26+
xor(x::Bool, y::Bool) = (x!=y)
2727

2828
>>(x::Bool, c::Unsigned) = Int(x) >> c
2929
<<(x::Bool, c::Unsigned) = Int(x) << c

‎base/broadcast.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ function broadcast_bitarrays(scalarf, bitf, A::AbstractArray{Bool}, B::AbstractA
498498
return F
499499
end
500500

501-
biteq(a::UInt64, b::UInt64) = ~a $ b
501+
biteq(a::UInt64, b::UInt64) = ~a b
502502
bitlt(a::UInt64, b::UInt64) = ~a & b
503-
bitneq(a::UInt64, b::UInt64) = a $ b
503+
bitneq(a::UInt64, b::UInt64) = a b
504504
bitle(a::UInt64, b::UInt64) = ~a | b
505505

506506
.==(A::AbstractArray{Bool}, B::AbstractArray{Bool}) = broadcast_bitarrays(==, biteq, A, B)

‎base/c.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,24 @@ function transcode(::Type{UInt16}, src::Vector{UInt8})
187187
push!(dst, a)
188188
a = b; continue
189189
elseif a < 0xe0 # 2-byte UTF-8
190-
push!(dst, 0x3080 $ (UInt16(a) << 6) $ b)
190+
push!(dst, xor(0x3080, UInt16(a) << 6, b))
191191
elseif i < n # 3/4-byte character
192192
c = src[i += 1]
193193
if -64 <= (c % Int8) # invalid UTF-8 (non-continuation)
194194
push!(dst, a, b)
195195
a = c; continue
196196
elseif a < 0xf0 # 3-byte UTF-8
197-
push!(dst, 0x2080 $ (UInt16(a) << 12) $ (UInt16(b) << 6) $ c)
197+
push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c))
198198
elseif i < n
199199
d = src[i += 1]
200200
if -64 <= (d % Int8) # invalid UTF-8 (non-continuation)
201201
push!(dst, a, b, c)
202202
a = d; continue
203203
elseif a == 0xf0 && b < 0x90 # overlong encoding
204-
push!(dst, 0x2080 $ (UInt16(b) << 12) $ (UInt16(c) << 6) $ d)
204+
push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d))
205205
else # 4-byte UTF-8
206206
push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4),
207-
0xdc80 $ (UInt16(c & 0xf) << 6) $ d)
207+
xor(0xdc80, UInt16(c & 0xf) << 6, d))
208208
end
209209
else # too short
210210
push!(dst, a, b, c)
@@ -273,7 +273,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16})
273273
a += 0x2840
274274
dst[j += 1] = 0xf0 | ((a >> 8) % UInt8)
275275
dst[j += 1] = 0x80 | ((a % UInt8) >> 2)
276-
dst[j += 1] = 0xf0 $ ((((a % UInt8) << 4) & 0x3f) $ (b >> 6) % UInt8)
276+
dst[j += 1] = xor(0xf0, ((a % UInt8) << 4) & 0x3f, (b >> 6) % UInt8)
277277
dst[j += 1] = 0x80 | ((b % UInt8) & 0x3f)
278278
else
279279
dst[j += 1] = 0xe0 | ((a >> 12) % UInt8)

‎base/char.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ in(x::Char, y::Char) = x == y
3333
isless(x::Char, y::Char) = UInt32(x) < UInt32(y)
3434

3535
const hashchar_seed = 0xd4d64234
36-
hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) $ UInt64(h))
36+
hash(x::Char, h::UInt) = hash_uint64(((UInt64(x)+hashchar_seed)<<32) UInt64(h))
3737

3838
-(x::Char, y::Char) = Int(x) - Int(y)
3939
-(x::Char, y::Integer) = Char(Int32(x) - Int32(y))

‎base/combinatorics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function isperm(A)
7373
n = length(A)
7474
used = falses(n)
7575
for a in A
76-
(0 < a <= n) && (used[a] $= true) || return false
76+
(0 < a <= n) && (used[a] = true) || return false
7777
end
7878
true
7979
end

‎base/complex.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ const hash_0_imag = hash(0, h_imag)
161161

162162
function hash(z::Complex, h::UInt)
163163
# TODO: with default argument specialization, this would be better:
164-
# hash(real(z), h $ hash(imag(z), h $ h_imag) $ hash(0, h $ h_imag))
165-
hash(real(z), h $ hash(imag(z), h_imag) $ hash_0_imag)
164+
# hash(real(z), h hash(imag(z), h h_imag) hash(0, h h_imag))
165+
hash(real(z), h hash(imag(z), h_imag) hash_0_imag)
166166
end
167167

168168
## generic functions of complex numbers ##

‎base/dSFMT.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ function dsfmt_jump_add!(dest::Vector{UInt64}, src::Vector{UInt64})
115115
while i <= N-diff
116116
j = i*2-1
117117
p = j + diff*2
118-
dest[j] $= src[p]
119-
dest[j+1] $= src[p+1]
118+
dest[j] = src[p]
119+
dest[j+1] = src[p+1]
120120
i += 1
121121
end
122122
while i <= N
123123
j = i*2-1
124124
p = j + (diff - N)*2
125-
dest[j] $= src[p]
126-
dest[j+1] $= src[p+1]
125+
dest[j] = src[p]
126+
dest[j+1] = src[p+1]
127127
i += 1
128128
end
129-
dest[N*2+1] $= src[N*2+1]
130-
dest[N*2+2] $= src[N*2+2]
129+
dest[N*2+1] = src[N*2+1]
130+
dest[N*2+2] = src[N*2+2]
131131
return dest
132132
end
133133

@@ -148,10 +148,10 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64})
148148
t1 = mts[a+1]
149149
L0 = mts[u]
150150
L1 = mts[u+1]
151-
mts[u] = (t0 << SL1) $ (L1 >> 32) $ (L1 << 32) $ mts[b]
152-
mts[u+1] = (t1 << SL1) $ (L0 >> 32) $ (L0 << 32) $ mts[b+1]
153-
mts[a] = (mts[u] >> SR) $ (mts[u] & MSK1) $ t0
154-
mts[a+1] = (mts[u+1] >> SR) $ (mts[u+1] & MSK2) $ t1
151+
mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b])
152+
mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1])
153+
mts[a] = xor(mts[u] >> SR, mts[u] & MSK1, t0)
154+
mts[a+1] = xor(mts[u+1] >> SR, mts[u+1] & MSK2, t1)
155155

156156
mts[end] = (mts[end] + 2) % (N*2)
157157
return mts

‎base/deprecated.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ for (Fun, func) in [(:IdFun, :identity),
304304
(:ConjFun, :conj),
305305
(:AndFun, :&),
306306
(:OrFun, :|),
307-
(:XorFun, :$),
307+
(:XorFun, :xor),
308308
(:AddFun, :+),
309309
(:DotAddFun, :.+),
310310
(:SubFun, :-),
@@ -1023,6 +1023,13 @@ end))
10231023

10241024
@deprecate ipermutedims(A::AbstractArray,p) permutedims(A, invperm(p))
10251025

1026+
# 18696
1027+
function ($)(x, y)
1028+
depwarn("`x \$ y` is deprecated. use `xor(x, y)` or `x ⊻ y` instead.", :$)
1029+
xor(x, y)
1030+
end
1031+
export $
1032+
10261033
@deprecate is (===)
10271034

10281035

‎base/docs/helpdb/Base.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -3340,8 +3340,9 @@ Compute the Dawson function (scaled imaginary error function) of `x`, defined by
33403340
dawson
33413341

33423342
"""
3343-
\$(x, y)
3343+
xor(x, y)
3344+
⊻(x, y)
33443345
33453346
Bitwise exclusive or.
33463347
"""
3347-
Base.:$(x, y)
3348+
Base.xor(x, y)

‎base/exports.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ export
205205
!==,
206206
,
207207
,
208-
$,
208+
xor,
209+
,
209210
%,
210211
÷,
211212
&,

‎base/fastmath.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mul_fast{T<:FloatTypes}(x::T, y::T, zs::T...) =
153153
cmp_fast{T<:FloatTypes}(x::T, y::T) = ifelse(x==y, 0, ifelse(x<y, -1, +1))
154154
function mod_fast{T<:FloatTypes}(x::T, y::T)
155155
r = rem(x,y)
156-
ifelse((r > 0) $ (y > 0), r+y, r)
156+
ifelse((r > 0) (y > 0), r+y, r)
157157
end
158158
end
159159

‎base/float.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ _default_type(T::Union{Type{Real},Type{AbstractFloat}}) = Float64
361361
## floating point arithmetic ##
362362
-(x::Float64) = box(Float64,neg_float(unbox(Float64,x)))
363363
-(x::Float32) = box(Float32,neg_float(unbox(Float32,x)))
364-
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) $ 0x8000)
364+
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) 0x8000)
365365

366366
for op in (:+,:-,:*,:/,:\,:^)
367367
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b)))
@@ -400,7 +400,7 @@ function mod{T<:AbstractFloat}(x::T, y::T)
400400
r = rem(x,y)
401401
if r == 0
402402
copysign(r,y)
403-
elseif (r > 0) $ (y > 0)
403+
elseif (r > 0) (y > 0)
404404
r+y
405405
else
406406
r
@@ -531,7 +531,7 @@ const hx_NaN = hx(UInt64(0), NaN, UInt(0 ))
531531

532532
hash(x::UInt64, h::UInt) = hx(x, Float64(x), h)
533533
hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h)
534-
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
534+
hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h)
535535

536536
hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h)
537537
hash(x::Float32, h::UInt) = hash(Float64(x), h)
@@ -577,7 +577,7 @@ function nextfloat(f::Union{Float16,Float32,Float64}, d::Integer)
577577
fu = fumax
578578
else
579579
du = da % U
580-
if fneg $ dneg
580+
if fneg dneg
581581
if du > fu
582582
fu = min(fumax, du - fu)
583583
fneg = !fneg

‎base/gmp.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module GMP
44

55
export BigInt
66

7-
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($),
7+
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
88
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
99
ndigits, promote_rule, rem, show, isqrt, string, powermod,
1010
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
@@ -194,7 +194,7 @@ function convert{T<:Signed}(::Type{T}, x::BigInt)
194194
else
195195
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError())
196196
y = x % T
197-
(x.size > 0) $ (y > 0) && throw(InexactError()) # catch overflow
197+
(x.size > 0) (y > 0) && throw(InexactError()) # catch overflow
198198
y
199199
end
200200
end
@@ -249,7 +249,7 @@ promote_rule{T<:Integer}(::Type{BigInt}, ::Type{T}) = BigInt
249249
for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul),
250250
(:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r),
251251
(:gcd, :gcd), (:lcm, :lcm),
252-
(:&, :and), (:|, :ior), (:$, :xor))
252+
(:&, :and), (:|, :ior), (:xor, :xor))
253253
@eval begin
254254
function ($fJ)(x::BigInt, y::BigInt)
255255
z = BigInt()
@@ -279,7 +279,7 @@ function invmod(x::BigInt, y::BigInt)
279279
end
280280

281281
# More efficient commutative operations
282-
for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:$, :xor))
282+
for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor))
283283
@eval begin
284284
function ($fJ)(a::BigInt, b::BigInt, c::BigInt)
285285
z = BigInt()

‎base/hashing.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ hash(x::ANY, h::UInt) = 3*object_id(x) - h
1414
function hash_64_64(n::UInt64)
1515
local a::UInt64 = n
1616
a = ~a + a << 21
17-
a = a $ a >> 24
17+
a = a a >> 24
1818
a = a + a << 3 + a << 8
19-
a = a $ a >> 14
19+
a = a a >> 14
2020
a = a + a << 2 + a << 4
21-
a = a $ a >> 28
21+
a = a a >> 28
2222
a = a + a << 31
2323
return a
2424
end
2525

2626
function hash_64_32(n::UInt64)
2727
local a::UInt64 = n
2828
a = ~a + a << 18
29-
a = a $ a >> 31
29+
a = a a >> 31
3030
a = a * 21
31-
a = a $ a >> 11
31+
a = a a >> 11
3232
a = a + a << 6
33-
a = a $ a >> 22
33+
a = a a >> 22
3434
return a % UInt32
3535
end
3636

3737
function hash_32_32(n::UInt32)
3838
local a::UInt32 = n
3939
a = a + 0x7ed55d16 + a << 12
40-
a = a $ 0xc761c23c $ a >> 19
40+
a = a 0xc761c23c a >> 19
4141
a = a + 0x165667b1 + a << 5
42-
a = a + 0xd3a2646c $ a << 9
42+
a = a + 0xd3a2646c a << 9
4343
a = a + 0xfd7046c5 + a << 3
44-
a = a $ 0xb55a4f09 $ a >> 16
44+
a = a 0xb55a4f09 a >> 16
4545
return a
4646
end
4747

0 commit comments

Comments
 (0)
Please sign in to comment.