diff --git a/NEWS.md b/NEWS.md index 36175073b60fb..53972589fa116 100644 --- a/NEWS.md +++ b/NEWS.md @@ -40,14 +40,17 @@ New language features characters, and operator symbols are not allowed in identifiers. Number-like characters cannot begin identifiers ([#5936]). - * Support for a limited number of infix Unicode operators ([#552], [#6582]): + * Define a limited number of infix Unicode operators ([#552], [#6582]): | Precedence class | Operators (with synonyms, if any) | ---------------- | --------------------------------- - | == | ≥ (>=) ≤ (<=) ≡ (===) ≠ (!=) ≢ (!==) .≥ (.>=) .≤ (.<=) .!= (.≠) ∈ (`in`) ∉ (`(x,y)->!in(x, y)`) ∋ (`(x,y)->in(y, x)`) ∌ (`(x,y)->!in(y, x)`) ⊆ (`issubset`) ⊈ (`(x,y)->!issubset(x, y)`) ⊊ (`(x,y)->x⊆y && x!=y`) ⊂ ⊄ | - | + | ⊕ ⊖ ⊞ ⊟ ∪ (`union`) ∨ ⊔ | - | * | ÷ (`div`) ⋅ (`dot`) ∘ × (`cross`) ∩ (`intersect`) ∧ ⊓ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ | - | unary | √ | + | == | ≥ (>=) ≤ (<=) ≡ (===) ≠ (!=) ≢ (!==) .≥ (.>=) .≤ (.<=) .!= (.≠) ∈ (`in`) ∉ (`(x,y)->!in(x, y)`) ∋ (`(x,y)->in(y, x)`) ∌ (`(x,y)->!in(y, x)`) ⊆ (`issubset`) ⊈ (`(x,y)->!issubset(x, y)`) ⊊ (`(x,y)->x⊆y && x!=y`) | + | + | ∪ (`union`) | + | * | ÷ (`div`) ⋅ (`dot`) ∘ × (`cross`) ∩ (`intersect`) | + | unary | √ ∛ | + + In addition to these, many of the Unicode operator symbols are parsed + as infix operators and are available for user-defined methods ([#6929]). * Improved reporting of syntax errors ([#6179]) diff --git a/base/exports.jl b/base/exports.jl index a0c47747b95cb..135b4c37ba8c4 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -451,6 +451,7 @@ export widemul, zero, √, + ∛, # specfun airy, diff --git a/base/operators.jl b/base/operators.jl index 98ede76cd482f..8ac9a6ed72540 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -363,7 +363,7 @@ function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray) end # some operators not defined yet -global //, .>>, .<<, >:, <|, |>, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √ +global //, .>>, .<<, >:, <|, |>, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √, ∛ module Operators @@ -429,6 +429,7 @@ export ∩, ∪, √, + ∛, colon, hcat, vcat, @@ -442,6 +443,6 @@ import Base: !, !=, $, %, .%, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>, .>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>, <|, |>, \, ^, |, ~, !==, >:, colon, hcat, vcat, hvcat, getindex, setindex!, transpose, ctranspose, - ≥, ≤, ≠, .≥, .≤, .≠, ÷, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √ + ≥, ≤, ≠, .≥, .≤, .≠, ÷, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √, ∛ end diff --git a/base/sysimg.jl b/base/sysimg.jl index 0d1cf2921708d..87e9298235b40 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -118,6 +118,7 @@ include("floatfuncs.jl") include("math.jl") importall .Math const (√)=sqrt +const (∛)=cbrt include("float16.jl") # multidimensional arrays diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index f6679fbe0e617..a8242e19b57fb 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -2884,6 +2884,7 @@ Mathematical Functions .. function:: sqrt(x) Return :math:`\sqrt{x}`. Throws ``DomainError`` for negative ``Real`` arguments. Use complex negative arguments instead. + The prefix operator ``√`` is equivalent to ``sqrt``. .. function:: isqrt(n) @@ -2891,7 +2892,7 @@ Mathematical Functions .. function:: cbrt(x) - Return :math:`x^{1/3}` + Return :math:`x^{1/3}`. The prefix operator ``∛`` is equivalent to ``cbrt``. .. function:: erf(x) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index a2df58dba2450..8a2124e4d649d 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -8,16 +8,16 @@ (define prec-conditional '(?)) (define prec-lazy-or '(|\|\||)) (define prec-lazy-and '(&&)) -(define prec-arrow '(-- -->)) +(define prec-arrow '(-- --> ← → ↔ ↚ ↛ ↠ ↣ ↦ ↮ ⇎ ⇏ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⭄ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← →)) (define prec-comparison - '(> < >= ≥ <= ≤ == === ≡ != ≠ !== ≢ |.>| |.<| |.>=| |.≥| |.<=| |.≤| |.==| |.!=| |.≠| |.=| |.!| |<:| |>:| ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊)) + '(> < >= ≥ <= ≤ == === ≡ != ≠ !== ≢ |.>| |.<| |.>=| |.≥| |.<=| |.≤| |.==| |.!=| |.≠| |.=| |.!| |<:| |>:| ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊ ∝ ∊ ∍ ∥ ∦ ∷ ∺ ∻ ∼ ∽ ∾ ≁ ≃ ≄ ≅ ≆ ≇ ≈ ≉ ≊ ≋ ≌ ≍ ≎ ≐ ≑ ≒ ≓ ≔ ≕ ≖ ≗ ≘ ≙ ≚ ≛ ≜ ≝ ≞ ≟ ≣ ≦ ≧ ≨ ≩ ≪ ≫ ≬ ≭ ≮ ≯ ≰ ≱ ≲ ≳ ≴ ≵ ≶ ≷ ≸ ≹ ≺ ≻ ≼ ≽ ≾ ≿ ⊀ ⊁ ⊃ ⊅ ⊇ ⊉ ⊋ ⊏ ⊐ ⊑ ⊒ ⊜ ⊩ ⊬ ⊮ ⊰ ⊱ ⊲ ⊳ ⊴ ⊵ ⊶ ⊷ ⋍ ⋐ ⋑ ⋕ ⋖ ⋗ ⋘ ⋙ ⋚ ⋛ ⋜ ⋝ ⋞ ⋟ ⋠ ⋡ ⋢ ⋣ ⋤ ⋥ ⋦ ⋧ ⋨ ⋩ ⋪ ⋫ ⋬ ⋭ ⋲ ⋳ ⋴ ⋵ ⋶ ⋷ ⋸ ⋹ ⋺ ⋻ ⋼ ⋽ ⋾ ⋿ ⟈ ⟉ ⟒ ⦷ ⧀ ⧁ ⧡ ⧣ ⧤ ⧥ ⩦ ⩧ ⩪ ⩫ ⩬ ⩭ ⩮ ⩯ ⩰ ⩱ ⩲ ⩳ ⩴ ⩵ ⩶ ⩷ ⩸ ⩹ ⩺ ⩻ ⩼ ⩽ ⩾ ⩿ ⪀ ⪁ ⪂ ⪃ ⪄ ⪅ ⪆ ⪇ ⪈ ⪉ ⪊ ⪋ ⪌ ⪍ ⪎ ⪏ ⪐ ⪑ ⪒ ⪓ ⪔ ⪕ ⪖ ⪗ ⪘ ⪙ ⪚ ⪛ ⪜ ⪝ ⪞ ⪟ ⪠ ⪡ ⪢ ⪣ ⪤ ⪥ ⪦ ⪧ ⪨ ⪩ ⪪ ⪫ ⪬ ⪭ ⪮ ⪯ ⪰ ⪱ ⪲ ⪳ ⪴ ⪵ ⪶ ⪷ ⪸ ⪹ ⪺ ⪻ ⪼ ⪽ ⪾ ⪿ ⫀ ⫁ ⫂ ⫃ ⫄ ⫅ ⫆ ⫇ ⫈ ⫉ ⫊ ⫋ ⫌ ⫍ ⫎ ⫏ ⫐ ⫑ ⫒ ⫓ ⫔ ⫕ ⫖ ⫗ ⫘ ⫙ ⫷ ⫸ ⫹ ⫺)) (define prec-pipe '(|\|>| |<\||)) (define prec-colon '(: |..|)) -(define prec-plus '(+ - ⊕ ⊖ ⊞ ⊟ |.+| |.-| |\|| ∪ ∨ $ ⊔)) +(define prec-plus '(+ - ⊕ ⊖ ⊞ ⊟ |.+| |.-| |\|| ∪ ∨ $ ⊔ ± ∓ ∔ ∸ ≂ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣)) (define prec-bitshift '(<< >> >>> |.<<| |.>>| |.>>>|)) -(define prec-times '(* / |./| ÷ % ⋅ ∘ × |.%| |.*| |\\| |.\\| & ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓)) +(define prec-times '(* / |./| ÷ % ⋅ ∘ × |.%| |.*| |\\| |.\\| & ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍)) (define prec-rational '(// .//)) -(define prec-power '(^ |.^|)) +(define prec-power '(^ |.^| ↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓ ⥉ ⥌ ⥍ ⥏ ⥑ ⥔ ⥕ ⥘ ⥙ ⥜ ⥝ ⥠ ⥡ ⥣ ⥥ ⥮ ⥯ ↑ ↓)) (define prec-decl '(|::|)) (define prec-dot '(|.|)) @@ -45,7 +45,7 @@ (eval `(define ,(symbol (string "is-" name "?")) (Set ,name)))) prec-names) -(define unary-ops '(+ - ! ~ |<:| |>:| √)) +(define unary-ops '(+ - ! ~ |<:| |>:| √ ∛ ∜)) ; operators that are both unary and binary (define unary-and-binary-ops '(+ - $ & ~)) @@ -63,7 +63,7 @@ (define ctrans-op (string->symbol "'")) (define vararg-op (string->symbol "...")) -(define operators (list* '~ '! '-> '√ ctrans-op trans-op vararg-op +(define operators (list* '~ '! '-> '√ '∛ '∜ ctrans-op trans-op vararg-op (delete-duplicates (apply append (map eval prec-names)))))