Added example for associativity

Hopefully this change makes this neat feature more apparent
This commit is contained in:
apense 2015-06-24 23:30:03 -04:00
commit f8870280d7

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