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

Addition of Unicode counterparts of some common operators. #41787

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions base/exports.jl
Expand Up @@ -172,6 +172,7 @@ export
≠,
!==,
≡,
⩶,
≢,
xor,
⊻,
Expand All @@ -188,15 +189,22 @@ export
/,
//,
<,
≮,
<:,
<<,
<=,
≤,
⩽,
≰,
==,
⩵,
>,
≯,
>:,
>=,
≥,
⩾,
≱,
>>,
>>>,
\,
Expand Down
175 changes: 169 additions & 6 deletions base/operators.jl
Expand Up @@ -47,6 +47,7 @@ supertype(T::UnionAll) = (@_total_meta; UnionAll(T.var, supertype(T.body)))

"""
==(x, y)
⩵(x, y)

Generic equality operator. Falls back to [`===`](@ref).
Should be implemented for all types with a notion of equality, based on the abstract value
Expand Down Expand Up @@ -77,6 +78,7 @@ If some type defines `==`, [`isequal`](@ref), and [`isless`](@ref) then it shoul
also implement [`<`](@ref) to ensure consistency of comparisons.
"""
==
const ⩵ = ==

"""
isequal(x, y)
Expand Down Expand Up @@ -249,7 +251,7 @@ isunordered(x::Missing) = true

"""
!=(x, y)
≠(x,y)
≠(x, y)

Not-equals comparison operator. Always gives the opposite answer as [`==`](@ref).

Expand All @@ -270,8 +272,9 @@ false
const ≠ = !=

"""
===(x,y) -> Bool
≡(x,y) -> Bool
===(x, y) -> Bool
≡(x, y) -> Bool
stevengj marked this conversation as resolved.
Show resolved Hide resolved
⩶(x, y) -> Bool

Determine whether `x` and `y` are identical, in the sense that no program could distinguish
them. First the types of `x` and `y` are compared. If those are identical, mutable objects
Expand All @@ -295,10 +298,11 @@ true
"""
===
const ≡ = ===
const ⩶ = ===

"""
!==(x, y)
≢(x,y)
≢(x, y)

Always gives the opposite answer as [`===`](@ref).

Expand Down Expand Up @@ -342,6 +346,28 @@ false
"""
<(x, y) = isless(x, y)

"""
≮(x, y)

Not-less-than comparison operator. Always gives the opposite answer as [`<`](@ref).

# Examples
```jldoctest
julia> 'a' ≮ 'b'
false

julia> "abc" ≮ "abd"
false

julia> 5 ≮ 3
true
```

!!! compat "Julia 1.8"
The ≮ operator requires at least Julia 1.8.
"""
≮(x, y) = !<(x, y)

"""
>(x, y)

Expand All @@ -368,9 +394,35 @@ true
"""
>(x, y) = y < x

"""
≯(x, y)

Not-greater-than comparison operator. Always gives the opposite answer as [`>`](@ref).

# Examples
```jldoctest
julia> 'a' ≯ 'b'
true

julia> 1 ≯ 3 ≯ 7
true

julia> "abc" ≯ "abd"
true

julia> 5 ≯ 3
false
```

!!! compat "Julia 1.8"
The ≯ operator requires at least Julia 1.8.
"""
≯(x, y) = !>(x, y)

"""
<=(x, y)
≤(x,y)
≤(x, y)
⩽(x, y)

Less-than-or-equals comparison operator. Falls back to `(x < y) | (x == y)`.

Expand All @@ -388,13 +440,43 @@ true
julia> 5 <= 3
false
```

!!! compat "Julia 1.8"
The ⩽ operator requires at least Julia 1.8.
"""
<=(x, y) = (x < y) | (x == y)
const ≤ = <=
const ⩽ = ≤

"""
≰(x, y)

Not-less-than-or-equals comparison operator. Always gives the opposite answer as [`≤`](@ref).

# Examples
```jldoctest
julia> 'a' ≰ 'b'
false

julia> 9 ≰ 8 ≰ 7
true

julia> "abc" ≰ "abc"
false

julia> 5 ≰ 3
true
```

!!! compat "Julia 1.8"
The ≰ operator requires at least Julia 1.8.
"""
≰(x, y) = !≤(x, y)

"""
>=(x, y)
≥(x,y)
≥(x, y)
⩾(x, y)

Greater-than-or-equals comparison operator. Falls back to `y <= x`.

Expand All @@ -412,9 +494,38 @@ true
julia> 5 >= 3
true
```

!!! compat "Julia 1.8"
The ⩾ operator requires at least Julia 1.8.
"""
>=(x, y) = (y <= x)
const ≥ = >=
const ⩾ = ≥

"""
≱(x, y)

Not-greater-than-or-equals comparison operator. Always gives the opposite answer as [`≥`](@ref).

# Examples
```jldoctest
julia> 'a' ≱ 'b'
true

julia> 3 ≱ 5 ≱ 7
true

julia> "abc" ≱ "abc"
false

julia> 5 ≱ 3
false
```

!!! compat "Julia 1.8"
The ≱ operator requires at least Julia 1.8.
"""
≱(x, y) = !≥(x, y)

# this definition allows Number types to implement < instead of isless,
# which is more idiomatic:
Expand Down Expand Up @@ -1149,6 +1260,19 @@ used to implement specialized methods.
"""
>=(x) = Fix2(>=, x)

"""
≱(x)

Create a function that compares its argument to `x` using [`≱`](@ref), i.e.
a function equivalent to `y -> y ≱ x`.
The returned function is of type `Base.Fix2{typeof(≱)}`, which can be
used to implement specialized methods.

!!! compat "Julia 1.8"
This functionality requires at least Julia 1.8.
"""
≱(x) = Fix2(≱, x)

"""
<=(x)

Expand All @@ -1162,6 +1286,19 @@ used to implement specialized methods.
"""
<=(x) = Fix2(<=, x)

"""
≰(x)

Create a function that compares its argument to `x` using [`≰`](@ref), i.e.
a function equivalent to `y -> y ≰ x`.
The returned function is of type `Base.Fix2{typeof(≰)}`, which can be
used to implement specialized methods.

!!! compat "Julia 1.8"
This functionality requires at least Julia 1.8.
"""
≰(x) = Fix2(≰, x)

"""
>(x)

Expand All @@ -1175,6 +1312,19 @@ used to implement specialized methods.
"""
>(x) = Fix2(>, x)

"""
≯(x)

Create a function that compares its argument to `x` using [`≯`](@ref), i.e.
a function equivalent to `y -> y ≯ x`.
The returned function is of type `Base.Fix2{typeof(≯)}`, which can be
used to implement specialized methods.

!!! compat "Julia 1.8"
This functionality requires at least Julia 1.8.
"""
≯(x) = Fix2(≯, x)

"""
<(x)

Expand All @@ -1188,6 +1338,19 @@ used to implement specialized methods.
"""
<(x) = Fix2(<, x)

"""
≮(x)

Create a function that compares its argument to `x` using [`≮`](@ref), i.e.
a function equivalent to `y -> y ≮ x`.
The returned function is of type `Base.Fix2{typeof(≮)}`, which can be
used to implement specialized methods.

!!! compat "Julia 1.8"
This functionality requires at least Julia 1.8.
"""
≮(x) = Fix2(≮, x)

"""
Splat(f)

Expand Down