Skip to content

Commit 1d7b301

Browse files
committed
Distinguish between operators defined or not in Base
1 parent d46161e commit 1d7b301

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

doc/src/manual/mathematical-operations.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -403,22 +403,22 @@ Julia applies the following order and associativity of operations, from highest
403403
| Category | Operators | Associativity |
404404
|:-------------- |:------------------------------------------------------------------------------------------------- |:-------------------------- |
405405
| Syntax | `.` followed by `::` followed by `'` | Left |
406-
| Exponentiation | `^ ↑ ↓ ⇵` | Right[^1] |
407-
| Unary | `+ - ! ~ ¬ √ ∛ ∜ ⋆ ± ∓ <: >:` | Right[^2] |
406+
| Exponentiation | `^` (`↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓`, etc.) | Right[^1] |
407+
| Unary | `+ - ! ~ √ ∛ ∜ <: >:` (`¬ ⋆ ± ∓`) | Right[^2] |
408408
| Juxtaposition | Implicit multiplication by numeric literal coefficients; e.g., `2x` is parsed as `2*x` | Non-associative |
409409
| Bitshifts | `<< >> >>>` | Left |
410410
| Fractions | `//` | Left |
411-
| Multiplication | `* / % & \ ÷ ⋅ ∘ × ⋆ ⊗ ⊘ ⊠ ⊡ ⊓ ∧` | Left[^3] |
412-
| Addition | `+ - \| ⊕ ⊖ ⊞ ⊟ ++ ± ∓ ∪ ⊔ ∨ ⊽ ⊻` | Left[^3] |
413-
| Syntax | `: .. … ⁝ ⋮ ⋱ ⋰ ⋯` | Left |
411+
| Multiplication | `* / ÷ % & ∘ \ ∩ ⊼` (`× ⋆ ⊗ ⊘ ⊠ ⊡ ⊓ ∧`, etc.) | Left[^3] |
412+
| Addition | `+ - \| ∪ ⊻ ⊽` (`± ∓ ⊕ ⊖ ⊞ ⊟ ⊔ ∨`, etc.) | Left[^3] |
413+
| Syntax | `:` (`.. … ⁝ ⋮ ⋱ ⋰ ⋯`) | Left |
414414
| Syntax | `\|>` | Left |
415415
| Syntax | `<\|` | Right |
416-
| Comparisons | `> < >= <= == === != !== <:` | Non-associative[^4] |
416+
| Comparisons | `in isa > < >= <= == === != !== ≢ ∈ ∉ ∋ ∌ ⊆ ⊈ ⊊ ≈ ≉ ⊇ ⊉ ⊋ <: >:` (`⊂ ⊄ ∝ ∥`, etc.) | Non-associative[^4] |
417417
| Control flow | `&&` followed by `\|\|` | Right |
418-
| Arrows | `← → ↔ ↚ ↛ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔` | Right |
418+
| Arrows | (`← → ↔ ↚ ↛ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔`, etc.) | Right |
419419
| Control flow | `?` | Right |
420420
| Pair | `=>` | Right |
421-
| Assignments | `= += -= *= /= //= \= ^= ÷= %= \|= &= ⊻= <<= >>= >>>= ≔ ⩴ ≕ ~ := $=` | Right |
421+
| Assignments | `= += -= −= *= /= //= \= ^= ÷= %= <<= >>= >>>= \|= &= ⊻= ~` (`≔ ⩴ ≕ :=`) | Right |
422422

423423
[^1]:
424424
Unary operators and juxtaposition of numeric literals *within the exponent* take precedence. For example, `2^-3`, `x^√2`, and `2^3x` are parsed as `2^(-3)`, `x^(√2)`, and `2^(3*x)`; whereas `-2^3`, `√x^2`, `2^3*x`, and `2x^3` are parsed as `-(2^3)`, `√(x^2)`, `(2^3)*x`, and `2*(x^3)`.
@@ -430,22 +430,24 @@ Julia applies the following order and associativity of operations, from highest
430430
[^4]:
431431
Comparisons can be [chained](@ref "Chaining comparisons"). For example, `a < b < c` is essentially the same as `a < b && b < c`. However, the order of evaluation is undefined.
432432

433-
Most of these [operators are functions](@ref Operators-Are-Functions), some of which may already be defined in the
434-
`Base` module, but any of which can be given definitions by standard libraries, packages, or user code. They can
435-
also be used with either functional notation (e.g., `+(a, b)`) or "infix" notation (e.g., `a + b`).
436-
437-
Note that the lists of operators for arrows, comparisons, addition, multiplication, and exponentiation are incomplete;
438-
for a complete list of *every* Julia operator's precedence, see the top of this file:
439-
[`src/julia-parser.scm`](https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm). It is also possible to
440-
define additional operators by appending suffixes to most of the binary operators. The valid suffixes include the
441-
Unicode combining characters, along with the subscripts, superscripts, and various primes (`′ ″ ‴ ⁗ ‵ ‶ ‷`) listed in
433+
Most of these [operators are functions](@ref Operators-Are-Functions). They can also be used with either functional
434+
notation (e.g., `+(a, b)`) or "infix" notation (e.g., `a + b`). Those listed outside of parentheses are already
435+
defined in the `Base` module; those listed inside parentheses are not currently defined in `Base`, but are available
436+
to be defined by standard libraries, packages, or user code. For example, `` and `×` are defined in the standard
437+
library's `LinearAlgebra` package. Some of the latter lists are incomplete; for a complete listing of *every* Julia
438+
operator and its precedence, see the top of this file:
439+
[`src/julia-parser.scm`](https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm).
440+
441+
It is also possible to define additional operators by appending suffixes to most of the binary operators. The valid
442+
suffixes include the Unicode combining characters, along with the subscripts, superscripts, and various primes
443+
(`′ ″ ‴ ⁗ ‵ ‶ ‷`) listed in
442444
[`src/flisp/julia_opsuffs.h`](https://github.com/JuliaLang/julia/blob/master/src/flisp/julia_opsuffs.h). The
443-
resulting operators can be used with either functional or infix notation, and have the same precedence and associativity
444-
as the base operator. For example, `⋆̂ᵝ₁′` could be defined as a function, and used as an infix operator with the same
445-
precedence and associativity as `` and `*`. However, operators ending with a subscript or superscript letter should
446-
be followed by a space when used in infix notation to distinguish them from variable names that begin with a subscript
447-
or superscript letter. For example, if `+ᵃ` is an operator, then `+ᵃx` should be written as `+ᵃ x` to distinguish it
448-
from `+ ᵃx`.
445+
resulting operators can be used with either functional or infix notation, and have the same precedence and
446+
associativity as the base operator. For example, `⋆̂ᵝ₁′` could be defined as a function, and used as an infix operator
447+
with the same precedence and associativity as `` and `*`. However, operators ending with a subscript or superscript
448+
letter should be followed by a space when used in infix notation to distinguish them from variable names that begin
449+
with a subscript or superscript letter. For example, if `+ᵃ` is an operator, then `+ᵃx` should be written as `+ᵃ x`
450+
to distinguish it from `+ ᵃx`.
449451

450452
You can also find the numerical precedence for any binary or ternary operator via the
451453
built-in function `Base.operator_precedence`, where higher numbers take precedence:

0 commit comments

Comments
 (0)