Skip to content

Commit 1fb9a51

Browse files
committed
accept ∈ as a synonym for 'in' inside for loops and comprehensions (closes #8487)
1 parent 071390a commit 1fb9a51

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Julia v0.5.0 Release Notes
44
New language features
55
---------------------
66

7+
* `x ∈ X` is now a synonym for `x in X` in `for` loops and comprehensions,
8+
as it already was in comparisons ([#13824]).
9+
710
Language changes
811
----------------
912

@@ -1589,6 +1592,7 @@ Too numerous to mention.
15891592
[#7917]: https://github.com/JuliaLang/julia/issues/7917
15901593
[#7992]: https://github.com/JuliaLang/julia/issues/7992
15911594
[#8011]: https://github.com/JuliaLang/julia/issues/8011
1595+
[#8036]: https://github.com/JuliaLang/julia/issues/8036
15921596
[#8089]: https://github.com/JuliaLang/julia/issues/8089
15931597
[#8113]: https://github.com/JuliaLang/julia/issues/8113
15941598
[#8135]: https://github.com/JuliaLang/julia/issues/8135
@@ -1736,6 +1740,8 @@ Too numerous to mention.
17361740
[#13465]: https://github.com/JuliaLang/julia/issues/13465
17371741
[#13496]: https://github.com/JuliaLang/julia/issues/13496
17381742
[#13480]: https://github.com/JuliaLang/julia/issues/13480
1743+
[#13496]: https://github.com/JuliaLang/julia/issues/13496
17391744
[#13542]: https://github.com/JuliaLang/julia/issues/13542
17401745
[#13680]: https://github.com/JuliaLang/julia/issues/13680
17411746
[#13681]: https://github.com/JuliaLang/julia/issues/13681
1747+
[#13824]: https://github.com/JuliaLang/julia/issues/13824

doc/manual/control-flow.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ See :ref:`man-variables-and-scoping` for a detailed
483483
explanation of variable scope and how it works in Julia.
484484

485485
In general, the ``for`` loop construct can iterate over any container.
486-
In these cases, the alternative (but fully equivalent) keyword ``in`` is
487-
typically used instead of ``=``, since it makes the code read more
486+
In these cases, the alternative (but fully equivalent) keyword ``in``
487+
or `` is typically used instead of ``=``, since it makes the code read more
488488
clearly:
489489

490490
.. doctest::
@@ -496,7 +496,7 @@ clearly:
496496
4
497497
0
498498

499-
julia> for s in ["foo","bar","baz"]
499+
julia> for s ["foo","bar","baz"]
500500
println(s)
501501
end
502502
foo

src/julia-parser.scm

+2-1
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,8 @@
14141414
r)
14151415
((eq? r ':)
14161416
r)
1417-
((and (length= r 4) (eq? (car r) 'comparison) (eq? (caddr r) 'in))
1417+
((and (length= r 4) (eq? (car r) 'comparison)
1418+
(or (eq? (caddr r) 'in) (eq? (caddr r) '∈)))
14181419
`(= ,(cadr r) ,(cadddr r)))
14191420
(else
14201421
(error "invalid iteration specification")))))

test/core.jl

+9
Original file line numberDiff line numberDiff line change
@@ -3485,6 +3485,15 @@ end
34853485
@test foo13855(Base.AddFun())() == Base.AddFun()
34863486
@test foo13855(Base.MulFun())() == Base.MulFun()
34873487

3488+
# issue #8487
3489+
@test [x for x in 1:3] == [x for x 1:3] == [x for x = 1:3]
3490+
let A = Array(Int, 4,3)
3491+
for i 1:size(A,1), j 1:size(A,2)
3492+
A[i,j] = 17*i + 51*j
3493+
end
3494+
@test A == [17*i + 51*j for i 1:size(A,1), j 1:size(A,2)]
3495+
end
3496+
34883497
# check if finalizers for the old gen can be triggered manually
34893498
# issue #13986
34903499
let

0 commit comments

Comments
 (0)