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

add <: to add-dots #35085

Merged
merged 15 commits into from
May 6, 2020
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ Language changes
Now the result is "a\n b", since the space before `b` is no longer considered to occur
at the start of a line. The old behavior is considered a bug ([#35001]).

stevengj marked this conversation as resolved.
Show resolved Hide resolved
* `<:` and `>:` can now be broadcasted over arrays with `.<:` and `.>:` ([#35085])

* Color now defaults to on when stdout and stderr are TTYs ([#34347])
stevengj marked this conversation as resolved.
Show resolved Hide resolved


Multi-threading changes
-----------------------

Expand Down
3 changes: 3 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,9 @@ function __dot__(x::Expr)
elseif (x.head === :(=) || x.head === :function || x.head === :macro) &&
Meta.isexpr(x.args[1], :call) # function or macro definition
Expr(x.head, x.args[1], dotargs[2])
elseif x.head === :(<:) || x.head === :(>:)
tmp = x.head === :(<:) ? :(.<:) : :(.>:)
Expr(:call, tmp, dotargs...)
else
if x.head === :&& || x.head === :||
error("""
Expand Down
2 changes: 1 addition & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(define prec-conditional '(?))
(define prec-arrow (append!
'(-- -->)
(add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻))))
(add-dots '(← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻ <: >:))))
(define prec-lazy-or '(|\|\||))
(define prec-lazy-and '(&&))
(define prec-comparison
Expand Down
7 changes: 7 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ end
# 28680
@test 1 .+ 1 .+ (1, 2) == (3, 4)


stevengj marked this conversation as resolved.
Show resolved Hide resolved
# PR #35260 no allocations in simple broadcasts
u = rand(100)
k1 = similar(u)
Expand All @@ -867,3 +868,9 @@ k4 = similar(u)
f(a,b,c,d,e) = @. a = a + 1*(b+c+d+e)
@allocated f(u,k1,k2,k3,k4)
@test (@allocated f(u,k1,k2,k3,k4)) == 0

ret = @macroexpand @.([Int, Number] <: Real)
@test ret == :([Int, Number] .<: Real)

ret = @macroexpand @.([Int, Number] >: Real)
@test ret == :([Int, Number] .>: Real)
11 changes: 11 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,14 @@ end
@test Meta.parse("±x") == Expr(:call, :±, :x)
@test Meta.parse("∓x") == Expr(:call, :∓, :x)
end

@testset "test .<: and .>:" begin
tmp = [Int, Float64, String, Bool] .<: Union{Int, String}
@test tmp == Bool[1, 0, 1, 0]

tmp = [Int, Float64, String, Bool] .>: [Int, Float64, String, Bool]
@test tmp == Bool[1, 1, 1, 1]
stevengj marked this conversation as resolved.
Show resolved Hide resolved

tmp = @. [Int, Float64, String, Bool] <: Union{Int, String}
@test tmp == Bool[1, 0,1, 0]
end