From b205f2a1812640b624dbc10ef0c893361358d68b Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 29 Oct 2015 22:53:39 -0400 Subject: [PATCH] =?UTF-8?q?accept=20=E2=88=88=20as=20a=20synonym=20for=20'?= =?UTF-8?q?in'=20inside=20for=20loops=20and=20comprehensions=20(closes=20#?= =?UTF-8?q?8487)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.md | 9 +++++++++ doc/manual/control-flow.rst | 6 +++--- src/julia-parser.scm | 3 ++- test/core.jl | 9 +++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5c514027923d8..506da90486aea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,9 @@ Julia v0.5.0 Release Notes New language features --------------------- + * `x ∈ X` is now a synonym for `x in X` in `for` loops and comprehensions, + as it already was in comparisons ([#13824]). + Language changes ---------------- @@ -1569,6 +1572,7 @@ Too numerous to mention. [#7917]: https://github.com/JuliaLang/julia/issues/7917 [#7992]: https://github.com/JuliaLang/julia/issues/7992 [#8011]: https://github.com/JuliaLang/julia/issues/8011 +[#8036]: https://github.com/JuliaLang/julia/issues/8036 [#8089]: https://github.com/JuliaLang/julia/issues/8089 [#8113]: https://github.com/JuliaLang/julia/issues/8113 [#8135]: https://github.com/JuliaLang/julia/issues/8135 @@ -1712,6 +1716,11 @@ Too numerous to mention. [#13062]: https://github.com/JuliaLang/julia/issues/13062 [#13338]: https://github.com/JuliaLang/julia/issues/13338 [#13387]: https://github.com/JuliaLang/julia/issues/13387 +[#13440]: https://github.com/JuliaLang/julia/issues/13440 [#13465]: https://github.com/JuliaLang/julia/issues/13465 [#13480]: https://github.com/JuliaLang/julia/issues/13480 +[#13496]: https://github.com/JuliaLang/julia/issues/13496 [#13542]: https://github.com/JuliaLang/julia/issues/13542 +[#13680]: https://github.com/JuliaLang/julia/issues/13680 +[#13681]: https://github.com/JuliaLang/julia/issues/13681 +[#13824]: https://github.com/JuliaLang/julia/issues/13824 diff --git a/doc/manual/control-flow.rst b/doc/manual/control-flow.rst index 143f0de971bf7..b2a4de4279b1e 100644 --- a/doc/manual/control-flow.rst +++ b/doc/manual/control-flow.rst @@ -483,8 +483,8 @@ See :ref:`man-variables-and-scoping` for a detailed explanation of variable scope and how it works in Julia. In general, the ``for`` loop construct can iterate over any container. -In these cases, the alternative (but fully equivalent) keyword ``in`` is -typically used instead of ``=``, since it makes the code read more +In these cases, the alternative (but fully equivalent) keyword ``in`` +or `∈` is typically used instead of ``=``, since it makes the code read more clearly: .. doctest:: @@ -496,7 +496,7 @@ clearly: 4 0 - julia> for s in ["foo","bar","baz"] + julia> for s ∈ ["foo","bar","baz"] println(s) end foo diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 543233921d834..45ba68d602c32 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1413,7 +1413,8 @@ r) ((eq? r ':) r) - ((and (length= r 4) (eq? (car r) 'comparison) (eq? (caddr r) 'in)) + ((and (length= r 4) (eq? (car r) 'comparison) + (or (eq? (caddr r) 'in) (eq? (caddr r) '∈))) `(= ,(cadr r) ,(cadddr r))) (else (error "invalid iteration specification"))))) diff --git a/test/core.jl b/test/core.jl index 6755bc6a775ff..a84996419d15d 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3473,3 +3473,12 @@ f11327{T}(::Type{T},x::T) = x let T=TypeVar(:T,true) @test typeintersect(Tuple{Type{T},T}, Tuple{Type{Type{Float64}},Type{Int}}) === Union{} end + +# issue #8487 +@test [x for x in 1:3] == [x for x ∈ 1:3] == [x for x = 1:3] +let A = Array(Int, 4,3) + for i ∈ 1:size(A,1), j ∈ 1:size(A,2) + A[i,j] = 17*i + 51*j + end + @test A == [17*i + 51*j for i ∈ 1:size(A,1), j ∈ 1:size(A,2)] +end