Skip to content

Commit

Permalink
Merge pull request #6582 from JuliaLang/uniops-552
Browse files Browse the repository at this point in the history
RFC: Add some unicode function synonyms and infix operators
  • Loading branch information
JeffBezanson committed May 5, 2014
2 parents 8f76835 + 970938e commit 4c4e7cb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
23 changes: 23 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,29 @@ export
# Operators
!,
!=,
,
!==,
,
,
$,
%,
&,
*,
+,
-,
.!=,
.≠,
.+,
.-,
.*,
./,
.<,
.<=,
.≤,
.==,
.>,
.>=,
.≥,
.\,
.^,
/,
Expand All @@ -215,9 +221,11 @@ export
<:,
<<,
<=,
,
==,
>,
>=,
,
>>,
#.>>,
#.<<,
Expand All @@ -227,6 +235,7 @@ export
|,
~,
:,
÷,
A_ldiv_B!,
A_ldiv_Bc,
A_ldiv_Bt,
Expand Down Expand Up @@ -442,6 +451,7 @@ export
unsigned,
widemul,
zero,
,

# specfun
airy,
Expand Down Expand Up @@ -660,6 +670,8 @@ export
triu!,
triu,
vecnorm,
,
×,

# sparse
etree,
Expand Down Expand Up @@ -746,6 +758,17 @@ export
union,
unique,
values,
,
,
,
,
,
,
,
,
,
,
,

# strings and text output
ascii,
Expand Down
3 changes: 2 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan,
besselj0, besselj1, besselj, bessely0, bessely1, bessely,
hankelh1, hankelh2, besseli, besselk, besselh,
beta, lbeta, eta, zeta, polygamma, invdigamma, digamma, trigamma,
erfinv, erfcinv
erfinv, erfcinv,

import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin,
acos, atan, asinh, acosh, atanh, sqrt, log2, log10,
Expand Down Expand Up @@ -284,6 +284,7 @@ sqrt(x::Float64) = box(Float64,sqrt_llvm(unbox(Float64,x)))
sqrt(x::Float32) = box(Float32,sqrt_llvm(unbox(Float32,x)))
sqrt(x::Real) = sqrt(float(x))
@vectorize_1arg Number sqrt
const =sqrt

for f in (:ceil, :trunc, :significand) # :rint, :nearbyint
@eval begin
Expand Down
33 changes: 30 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ isequal(T::Type, S::Type) = typeseq(T, S)
isequal(x,y) = is(x,y)
==(x,y) = isequal(x,y)
!=(x,y) = !(x==y)
const = !=
const = is
!==(x,y) = !is(x,y)

const = !==
< (x,y) = isless(x,y)
> (x,y) = y < x
<=(x,y) = !(y < x)
const = <=
>=(x,y) = (y <= x)
const = >=
.> (x,y) = y.<x
.>=(x,y) = y.<=x
const .≥ = .>=

# this definition allows Number types to implement < instead of isless,
# which is more idiomatic:
Expand Down Expand Up @@ -84,6 +89,8 @@ end
.!=(x::Number,y::Number) = x!=y
.< (x::Real,y::Real) = x<y
.<=(x::Real,y::Real) = x<=y
const .≤ = .<=
const .≠ = .!=

# core << >> and >>> takes Int32 as second arg
<<(x,y::Integer) = x << convert(Int32,y)
Expand All @@ -104,6 +111,7 @@ fld{T<:Real}(x::T, y::T) = convert(T,round((x-mod(x,y))/y))
# operator alias
const % = rem
.%(x::Real, y::Real) = x%y
const ÷ = div

# mod returns in [0,y) whereas mod1 returns in (0,y]
mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
Expand Down Expand Up @@ -343,7 +351,7 @@ function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray)
end

# some operators not defined yet
global //, .>>, .<<, >:, <|, |>, hcat, hvcat
global //, .>>, .<<, >:, <|, |>, hcat, hvcat, , ×, , , , , , , , ,

module Operators

Expand Down Expand Up @@ -380,6 +388,12 @@ export
==,
>,
>=,
,
,
,
.≥,
.≤,
.≠,
>>,
.>>,
.<<,
Expand All @@ -390,6 +404,18 @@ export
|>,
<|,
~,
÷,
,
×,
,
,
,
,
,
,
,
,
,
colon,
hcat,
vcat,
Expand All @@ -402,6 +428,7 @@ export
import Base: !, !=, $, %, .%, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>,
.>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>,
<|, |>, \, ^, |, ~, !==, >:, colon, hcat, vcat, hvcat, getindex, setindex!,
transpose, ctranspose
transpose, ctranspose,
, , , .≥, .≤, .≠, ÷, , ×, , , , , , , , ,

end
4 changes: 4 additions & 0 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function in(x, itr)
end
return false
end
const = in
(x, itr)=!(x, itr)
(itr, x)= (x, itr)
(itr, x)=!(itr, x)

function contains(itr, x)
depwarn("contains(collection, item) is deprecated, use in(item, collection) instead", :contains)
Expand Down
5 changes: 5 additions & 0 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function union(s::Set, sets::Set...)
end
return u
end
const = union

intersect(s::Set) = copy(s)
function intersect(s::Set, sets::Set...)
Expand All @@ -64,6 +65,7 @@ function intersect(s::Set, sets::Set...)
end
return i
end
const = intersect

function setdiff(a::Set, b::Set)
d = copy(a)
Expand All @@ -85,6 +87,9 @@ function issubset(l, r)
end
return true
end
const = issubset
(l::Set, r::Set) = (l, r) && l!=r
(l::Set, r::Set) = !(l, r)

function unique(C)
out = Array(eltype(C),0)
Expand Down
2 changes: 2 additions & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ include("sparse.jl")
importall .SparseMatrix
include("linalg.jl")
importall .LinAlg
const = dot
const × = cross
include("broadcast.jl")
importall .Broadcast

Expand Down
6 changes: 3 additions & 3 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
; the way the lexer works, every prefix of an operator must also
; be an operator.
(-- -->)
(> < >= <= == === != !== |.>| |.<| |.>=| |.<=| |.==| |.!=| |.=| |.!| |<:| |>:|)
(> < >= <= == === != !== |.>| |.<| |.>=| |.≥| |.<=| |.≤| |.==| |.!=| |.≠| |.=| |.!| |<:| |>:| ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊)
(|\|>| |<\||)
(: |..|)
(+ - |.+| |.-| |\|| $)
(+ - ⊕ ⊖ ⊞ ⊟ |.+| |.-| |\|| ∪ ∨ $ ⊓)
(<< >> >>> |.<<| |.>>| |.>>>|)
(* / |./| % |.%| & |.*| |\\| |.\\|)
(* / |./| ÷ % ⋅ ∘ × |.%| |.*| |\\| |.\\| & ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊔)
(// .//)
(^ |.^|)
(|::|)
Expand Down

0 comments on commit 4c4e7cb

Please sign in to comment.