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

accept ∈ as a synonym for 'in' inside for loops and comprehensions #13824

Merged
merged 1 commit into from
Dec 8, 2015
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
6 changes: 6 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 @@ -1589,6 +1592,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 @@ -1736,6 +1740,8 @@ Too numerous to mention.
[#13465]: https://github.com/JuliaLang/julia/issues/13465
[#13496]: https://github.com/JuliaLang/julia/issues/13496
[#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 @@ -1414,7 +1414,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 @@ -3485,6 +3485,15 @@ end
@test foo13855(Base.AddFun())() == Base.AddFun()
@test foo13855(Base.MulFun())() == Base.MulFun()

# 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

# check if finalizers for the old gen can be triggered manually
# issue #13986
let
Expand Down