summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorapense <apense@users.noreply.github.com>2015-06-24 23:30:03 -0400
committerapense <apense@users.noreply.github.com>2015-06-24 23:30:03 -0400
commitf8870280d7d0661da7187ee6be48c3c6419515f6 (patch)
treee940103c650f17e21759a67096b56e1dacbf0b75
parentbdd5a8c05ed1a92a4eb3056b4852df695d622285 (diff)
downloadNim-f8870280d7d0661da7187ee6be48c3c6419515f6.tar.gz
Added example for associativity
Hopefully this change makes this neat feature more apparent
-rw-r--r--doc/manual/syntax.txt17
1 files changed, 12 insertions, 5 deletions
diff --git a/doc/manual/syntax.txt b/doc/manual/syntax.txt
index 24644bce2..99af15948 100644
--- a/doc/manual/syntax.txt
+++ b/doc/manual/syntax.txt
@@ -15,15 +15,22 @@ Associativity
 Binary operators whose first character is ``^`` are right-associative, all
 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
 ----------
 
-Unary operators always bind stronger than any binary 
+Unary operators always bind stronger than any binary
 operator: ``$a + b`` is ``($a) + b`` and not ``$(a + b)``.
 
-If an unary operator's first character is ``@`` it is a `sigil-like`:idx: 
+If an unary operator's first character is ``@`` it is a `sigil-like`:idx:
 operator which binds stronger than a ``primarySuffix``: ``@x.abc`` is parsed
 as ``(@x).abc`` whereas ``$x.abc`` is parsed as ``$(x.abc)``.
 
@@ -34,7 +41,7 @@ following rules:
 Operators ending in either ``->``, ``~>`` or ``=>`` are called
 `arrow like`:idx:, and have the lowest precedence of all operators.
 
-If the operator ends with ``=`` and its first character is none of 
+If the operator ends with ``=`` and its first character is none of
 ``<``, ``>``, ``!``, ``=``, ``~``, ``?``, it is an *assignment operator* which
 has the second lowest precedence.
 
@@ -76,7 +83,7 @@ is still parsed as ``1 + (3 * 4)``, but ``1+3 * 4`` is parsed as ``(1+3) * 4``:
 
 
 Furthermore whether an operator is used a prefix operator is affected by the
-number of spaces: 
+number of spaces:
 
 .. code-block:: nim
   #! strongSpaces