summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorreactormonk <hafnersimon@gmail.com>2015-06-25 01:22:04 -0500
committerreactormonk <hafnersimon@gmail.com>2015-06-25 01:22:04 -0500
commit6f61264c498c4f229865e48fe4a4a945ec5c0c1d (patch)
tree459130a910513c1400bd070381294e5b42c23869
parente5e479c12e4dc561b795594ba6399cf86d7cb5c5 (diff)
parent4e129324f61bfff97fafc019e54809a84d85e9fe (diff)
downloadNim-6f61264c498c4f229865e48fe4a4a945ec5c0c1d.tar.gz
Merge pull request #2989 from apense/patch-11
Added example for var overloading
-rw-r--r--doc/manual/type_rel.txt15
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/manual/type_rel.txt b/doc/manual/type_rel.txt
index 5c8372e1e..97f7090b4 100644
--- a/doc/manual/type_rel.txt
+++ b/doc/manual/type_rel.txt
@@ -294,6 +294,21 @@ If the formal parameter ``f`` is of type ``var T`` in addition to the ordinary
 type checking, the argument is checked to be an `l-value`:idx:. ``var T``
 matches better than just ``T`` then.
 
+.. code-block:: nim
+  proc sayHi(x: int): string =
+    # matches a non-var int
+    result = $x
+  proc sayHi(x: var int): string =
+    # matches a var int
+    result = $(x + 10)
+    
+  proc sayHello(x: int) =
+    var m = x # a mutable version of x
+    echo sayHi(x) # matches the non-var version of sayHi
+    echo sayHi(m) # matches the var version of sayHi
+
+  sayHello(3) # 3
+              # 13
 
 Automatic dereferencing
 -----------------------