Merge pull request #2988 from apense/patch-10
Added example for associativity
This commit is contained in:
commit
e5e479c12e
1 changed files with 12 additions and 5 deletions
|
|
@ -15,7 +15,14 @@ Associativity
|
||||||
Binary operators whose first character is ``^`` are right-associative, all
|
Binary operators whose first character is ``^`` are right-associative, all
|
||||||
other binary operators are left-associative.
|
other binary operators are left-associative.
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
proc `^/`(x, y: float): float =
|
||||||
|
# a right-associative division operator
|
||||||
|
result = x / y
|
||||||
|
echo 12 ^/ 4 ^/ 8 # 24.0 (4 / 8 = 0.5, then
|
||||||
|
12 / 0.5 = 24.0)
|
||||||
|
echo 12 / 4 / 8 # 0.375 (12 / 4 = 3.0, then
|
||||||
|
3 / 8 = 0.375)
|
||||||
|
|
||||||
Precedence
|
Precedence
|
||||||
----------
|
----------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue