Skip to content

Commit

Permalink
accept ∈ as a synonym for 'in' inside for loops and comprehensions (c…
Browse files Browse the repository at this point in the history
…loses #8487)
  • Loading branch information
stevengj committed Oct 30, 2015
1 parent a36bb6d commit ecebf4e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions doc/manual/control-flow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -496,7 +496,7 @@ clearly:
4
0

julia> for s in ["foo","bar","baz"]
julia> for s ["foo","bar","baz"]
println(s)
end
foo
Expand Down
3 changes: 2 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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")))))
Expand Down
9 changes: 9 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ecebf4e

Please sign in to comment.