Merge pull request #2988 from apense/patch-10

Added example for associativity
This commit is contained in:
reactormonk 2015-06-25 01:21:10 -05:00
commit e5e479c12e

View file

@ -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
---------- ----------