diff --git a/NEWS.md b/NEWS.md index 69ac90ecc2b09..af1aee2f30135 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ New language features Language changes ---------------- + * The syntax `1.+2` is deprecated, since it is ambiguous: it could mean either + `1 .+ 2` (the current meaning) or `1. + 2` ([#19089]). Breaking changes ---------------- diff --git a/base/sparse/linalg.jl b/base/sparse/linalg.jl index 2e63f6b63dc83..c56f8a931229b 100644 --- a/base/sparse/linalg.jl +++ b/base/sparse/linalg.jl @@ -611,7 +611,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)))) end end end - scale!(X, 1./n) + scale!(X, 1 ./ n) iter = 0 local est diff --git a/doc/src/manual/mathematical-operations.md b/doc/src/manual/mathematical-operations.md index a6ff8bdea53f8..d23a27cdce942 100644 --- a/doc/src/manual/mathematical-operations.md +++ b/doc/src/manual/mathematical-operations.md @@ -169,6 +169,11 @@ For example, if you define `⊗(A,B) = kron(A,B)` to give a convenient infix syntax `A ⊗ B` for Kronecker products ([`kron`](@ref)), then `[A,B] .⊗ [C,D]` will compute `[A⊗C, B⊗D]` with no additional coding. +Combining dot operators with numeric literals can be ambiguous. +For example, it is not clear whether `1.+x` means `1. + x` or `1 .+ x`. +Therefore this syntax is disallowed, and spaces must be used around +the operator in such cases. + ## Numeric Comparisons Standard comparison operations are defined for all the primitive numeric types: diff --git a/src/julia-parser.scm b/src/julia-parser.scm index e15e23d7fb016..e8c5998ed69e0 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -306,7 +306,13 @@ (if (eqv? (peek-char port) #\.) (begin (read-char port) (if (dot-opchar? (peek-char port)) - (io.ungetc port #\.) + (begin + (if (not (eqv? (peek-char port) #\.)) + (let ((num (get-output-string str))) + (syntax-deprecation port + (string num #\. (peek-char port)) + (string num " ." (peek-char port))))) + (io.ungetc port #\.)) (begin (write-char #\. str) (read-digs #f #t) (if (eq? pred char-hex?) diff --git a/test/arrayops.jl b/test/arrayops.jl index 56a06f325628a..d4a3e1ba01735 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -16,31 +16,31 @@ using TestHelpers.OAs @test length((1,)) == 1 @test length((1,2)) == 2 - @test isequal(1.+[1,2,3], [2,3,4]) - @test isequal([1,2,3].+1, [2,3,4]) - @test isequal(1.-[1,2,3], [0,-1,-2]) - @test isequal([1,2,3].-1, [0,1,2]) + @test isequal(1 .+ [1,2,3], [2,3,4]) + @test isequal([1,2,3] .+ 1, [2,3,4]) + @test isequal(1 .- [1,2,3], [0,-1,-2]) + @test isequal([1,2,3] .- 1, [0,1,2]) @test isequal(5*[1,2,3], [5,10,15]) @test isequal([1,2,3]*5, [5,10,15]) - @test isequal(1./[1,2,5], [1.0,0.5,0.2]) + @test isequal(1 ./ [1,2,5], [1.0,0.5,0.2]) @test isequal([1,2,3]/5, [0.2,0.4,0.6]) - @test isequal(2.%[1,2,3], [0,0,2]) - @test isequal([1,2,3].%2, [1,0,1]) - @test isequal(2.÷[1,2,3], [2,1,0]) - @test isequal([1,2,3].÷2, [0,1,1]) - @test isequal(-2.%[1,2,3], [0,0,-2]) + @test isequal(2 .% [1,2,3], [0,0,2]) + @test isequal([1,2,3] .% 2, [1,0,1]) + @test isequal(2 .÷ [1,2,3], [2,1,0]) + @test isequal([1,2,3] .÷ 2, [0,1,1]) + @test isequal(-2 .% [1,2,3], [0,0,-2]) @test isequal([-1,-2,-3].%2, [-1,0,-1]) - @test isequal(-2.÷[1,2,3], [-2,-1,0]) - @test isequal([-1,-2,-3].÷2, [0,-1,-1]) + @test isequal(-2 .÷ [1,2,3], [-2,-1,0]) + @test isequal([-1,-2,-3] .÷ 2, [0,-1,-1]) - @test isequal(1.<<[1,2,5], [2,4,32]) - @test isequal(128.>>[1,2,5], [64,32,4]) - @test isequal(2.>>1, 1) - @test isequal(1.<<1, 2) - @test isequal([1,2,5].<<[1,2,5], [2,8,160]) - @test isequal([10,20,50].>>[1,2,5], [5,5,1]) + @test isequal(1 .<< [1,2,5], [2,4,32]) + @test isequal(128 .>> [1,2,5], [64,32,4]) + @test isequal(2 .>> 1, 1) + @test isequal(1 .<< 1, 2) + @test isequal([1,2,5] .<< [1,2,5], [2,8,160]) + @test isequal([10,20,50] .>> [1,2,5], [5,5,1]) a = ones(2,2) @@ -1182,8 +1182,8 @@ end @test [1,2] ⊙ [3,4] == 11 end - @test_throws DomainError (10.^[-1])[1] == 0.1 - @test (10.^[-1.])[1] == 0.1 + @test_throws DomainError (10 .^ [-1])[1] == 0.1 + @test (10 .^ [-1.])[1] == 0.1 end end diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index 74d26f0601c93..501acb6f9d2b2 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -278,7 +278,7 @@ end # Against vectorized versions @test norm(x,-Inf) ≈ minimum(abs.(x)) - @test norm(x,-1) ≈ inv(sum(1./abs.(x))) + @test norm(x,-1) ≈ inv(sum(1 ./ abs.(x))) @test norm(x,0) ≈ sum(x .!= 0) @test norm(x,1) ≈ sum(abs.(x)) @test norm(x) ≈ sqrt(sum(abs2.(x))) @@ -362,7 +362,7 @@ end ## Issue related tests @testset "issue #1447" begin - A = [1.+0.0im 0; 0 1] + A = [1.0+0.0im 0; 0 1] B = pinv(A) for i = 1:4 @test A[i] ≈ B[i] diff --git a/test/parse.jl b/test/parse.jl index d07c558179be9..07b9c93bdab95 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -21,9 +21,9 @@ end # issue #9684 let undot(op) = Symbol(string(op)[2:end]) - for (ex1, ex2) in [("5.≠x", "5.!=x"), - ("5.≥x", "5.>=x"), - ("5.≤x", "5.<=x")] + for (ex1, ex2) in [("5 .≠ x", "5 .!= x"), + ("5 .≥ x", "5 .>= x"), + ("5 .≤ x", "5 .<= x")] ex1 = parse(ex1); ex2 = parse(ex2) @test ex1.head === :call && (ex1.head === ex2.head) @test ex1.args[2] === 5 && ex2.args[2] === 5 diff --git a/test/perf/kernel/laplace.jl b/test/perf/kernel/laplace.jl index 010adc2bd43e0..9c8365872a18c 100644 --- a/test/perf/kernel/laplace.jl +++ b/test/perf/kernel/laplace.jl @@ -5,7 +5,7 @@ function laplace_iter_devec(u, dx2, dy2, Niter, N) for iter = 1:Niter for i = 2:N-1 for j = 2:N-1 - uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1./(2*(dx2+dy2))) + uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1 ./ (2*(dx2+dy2))) end end u, uout = uout, u @@ -24,7 +24,7 @@ end function laplace_iter_vec(u, dx2, dy2, Niter, N) for i = 1:Niter - u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1./ (2*(dx2+dy2))) + u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1 ./ (2*(dx2+dy2))) end return u end @@ -40,7 +40,7 @@ end function laplace_iter_vec_sub(u, dx2, dy2, Niter, N) for i = 1:Niter - u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1./ (2*(dx2+dy2))) + u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1 ./ (2*(dx2+dy2))) end return u end diff --git a/test/perf/kernel/raytracer.jl b/test/perf/kernel/raytracer.jl index 78c1a131f95a5..b3451222f4402 100644 --- a/test/perf/kernel/raytracer.jl +++ b/test/perf/kernel/raytracer.jl @@ -129,7 +129,7 @@ function Raytracer(levels, n, ss) g = 0. for dx in 0:1:(ss-1) for dy in 0:1:(ss-1) - d = Vec(x+dx*1./ss-n/2., y+dy*1./ss-n/2., n*1.0) + d = Vec(x+dx*1.0/ss-n/2.0, y+dy*1.0/ss-n/2.0, n*1.0) ray = Ray(Vec(0., 0., -4.0), unitize(d)) g += ray_trace(light, ray, scene) end diff --git a/test/perf/micro/perf.jl b/test/perf/micro/perf.jl index 5f10f1023b3cf..e5686d98d079d 100644 --- a/test/perf/micro/perf.jl +++ b/test/perf/micro/perf.jl @@ -101,7 +101,7 @@ function pisumvec() s = 0.0 a = [1:10000] for j = 1:500 - s = sum(1./(a.^2)) + s = sum(1 ./ (a.^2)) end s end diff --git a/test/perf/spell/perf.jl b/test/perf/spell/perf.jl index c5a8dee8dc028..4e1bc813f4a22 100644 --- a/test/perf/spell/perf.jl +++ b/test/perf/spell/perf.jl @@ -92,7 +92,7 @@ function spelltest(tests; bias=0, verbose=false) end end - return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100.*bad/n), + return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100. * bad/n), "unknown"=>unknown, "secs"=>toc()) end diff --git a/test/ranges.jl b/test/ranges.jl index 30b87be782b72..4db7c8cab32ac 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -922,8 +922,8 @@ end @testset "logspace" begin n = 10; a = 2; b = 4 # test default values; n = 50, base = 10 - @test logspace(a, b) == logspace(a, b, 50) == 10.^linspace(a, b, 50) - @test logspace(a, b, n) == 10.^linspace(a, b, n) + @test logspace(a, b) == logspace(a, b, 50) == 10 .^ linspace(a, b, 50) + @test logspace(a, b, n) == 10 .^ linspace(a, b, n) for base in (10, 2, e) @test logspace(a, b, base=base) == logspace(a, b, 50, base=base) == base.^linspace(a, b, 50) @test logspace(a, b, n, base=base) == base.^linspace(a, b, n)