From 4e129324f61bfff97fafc019e54809a84d85e9fe Mon Sep 17 00:00:00 2001 From: apense Date: Wed, 24 Jun 2015 23:56:35 -0400 Subject: [PATCH] Added example for var overloading Simple example to demonstrate overloading in case technical lingo is confusing --- doc/manual/type_rel.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/manual/type_rel.txt b/doc/manual/type_rel.txt index 5c8372e1ec..97f7090b42 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 -----------------------