- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add some unicode function synonyms and infix operators #6582
Changes from 16 commits
0625671
2a26899
fae924a
67ce8b5
01d98fe
edf4e3d
7369326
ad12241
e81e2bb
73f65ed
6036e78
672ca6e
915ba49
efcc36b
971756a
3cd38a5
4a98190
a243cc6
e4fbbef
970938e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,34 +187,43 @@ export | |
# Operators | ||
!, | ||
!=, | ||
≠, | ||
!==, | ||
≡, | ||
≢, | ||
$, | ||
%, | ||
&, | ||
*, | ||
+, | ||
-, | ||
.!=, | ||
.≠, | ||
.+, | ||
.-, | ||
.*, | ||
./, | ||
.<, | ||
.<=, | ||
.≤, | ||
.==, | ||
.>, | ||
.>=, | ||
.≥, | ||
.\, | ||
.^, | ||
/, | ||
//, | ||
⫽, | ||
<, | ||
<:, | ||
<<, | ||
<=, | ||
≤, | ||
==, | ||
>, | ||
>=, | ||
≥, | ||
>>, | ||
#.>>, | ||
#.<<, | ||
|
@@ -224,6 +233,10 @@ export | |
|, | ||
~, | ||
:, | ||
⊗, | ||
÷, | ||
∣, | ||
∤, | ||
A_ldiv_B!, | ||
A_ldiv_Bc, | ||
A_ldiv_Bt, | ||
|
@@ -439,6 +452,7 @@ export | |
unsigned, | ||
widemul, | ||
zero, | ||
√, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to parse |
||
|
||
# specfun | ||
airy, | ||
|
@@ -657,6 +671,8 @@ export | |
triu!, | ||
triu, | ||
vecnorm, | ||
⋅, | ||
×, | ||
|
||
# sparse | ||
etree, | ||
|
@@ -743,6 +759,18 @@ export | |
union, | ||
unique, | ||
values, | ||
∈, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
∉, | ||
∋, | ||
∌, | ||
⊆, | ||
⊈, | ||
⊂, | ||
⊄, | ||
⊊, | ||
∩, | ||
∪, | ||
△, | ||
|
||
# strings and text output | ||
ascii, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,8 @@ export | |
tril!, | ||
triu!, | ||
vecnorm, | ||
⋅, | ||
×, | ||
|
||
# Operators | ||
\, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -90,6 +95,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) | ||
|
@@ -110,6 +117,10 @@ 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 ⊗ = kron | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought you said kron was not such a great idea? |
||
const ÷ = div | ||
∣(x::Real, y::Real) = y%x==0 #x∣y = x divides y | ||
∤(x::Real, y::Real) = !∣(x,y) | ||
|
||
# mod returns in [0,y) whereas mod1 returns in (0,y] | ||
mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y) | ||
|
@@ -396,6 +407,8 @@ export | |
|>, | ||
<|, | ||
~, | ||
⊗, | ||
÷, | ||
colon, | ||
hcat, | ||
vcat, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ function //(x::Complex, y::Complex) | |
yy = real(y*y') | ||
complex(real(xy)//yy, imag(xy)//yy) | ||
end | ||
const ⫽ = // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit marginal too since I'm not sure this is a particularly standard notation. |
||
|
||
function show(io::IO, x::Rational) | ||
if isinf(x) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,13 @@ | |
; the way the lexer works, every prefix of an operator must also | ||
; be an operator. | ||
(-- -->) | ||
(> < >= <= == === != !== |.>| |.<| |.>=| |.<=| |.==| |.!=| |.=| |.!| |<:| |>:|) | ||
(> < >= ≥ <= ≤ == === ≡ != ≠ !== ≢ |.>| |.<| |.>=| |.≥| |.<=| |.≤| |.==| |.!=| |.≠| |.=| |.!| |<:| |>:| ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊) | ||
(|\|>| |<\||) | ||
(: |..|) | ||
(+ - |.+| |.-| |\|| $) | ||
(+ - |.+| |.-| |\|| $ ∩ ∪ △) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't ∩ have the precedence of |
||
(<< >> >>> |.<<| |.>>| |.>>>|) | ||
(* / |./| % |.%| & |.*| |\\| |.\\|) | ||
(// .//) | ||
(* / |./| ÷ ∣ ∤ % ⋅ × |.%| & ⊗ |.*| |\\| |.\\|) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why stop here? Aren't there a lot more Unicode symbols that could potentially be infix operators? e.g. We might not provide any methods for these in |
||
(// .// ⫽) | ||
(^ |.^|) | ||
(|::|) | ||
(|.|))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit skeptical about this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me this is the Laplacian operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think the meaning of a unicode operator has to be utterly obvious and agreed-on to have a definition in Base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with that.