summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorKaushal Modi <kaushal.modi@gmail.com>2020-02-25 15:19:51 -0500
committerGitHub <noreply@github.com>2020-02-25 21:19:51 +0100
commite4ed19c12fcce046d990a918800d9031706e8b66 (patch)
tree3fbc61d6d1cf0642968763f31694f944390e0877 /doc
parentdb540a0223480134598fb4806c55510cdef36bf1 (diff)
downloadNim-e4ed19c12fcce046d990a918800d9031706e8b66.tar.gz
[backport] tut1: Update the proc overloading examples (#13497) [skip ci]
Diffstat (limited to 'doc')
-rw-r--r--doc/tut1.rst16
1 files changed, 11 insertions, 5 deletions
diff --git a/doc/tut1.rst b/doc/tut1.rst
index 9b411c932..6d54d88a3 100644
--- a/doc/tut1.rst
+++ b/doc/tut1.rst
@@ -743,13 +743,19 @@ Overloaded procedures
 Nim provides the ability to overload procedures similar to C++:
 
 .. code-block:: nim
-  proc toString(x: int): string = ...
+  proc toString(x: int): string =
+    result =
+      if x < 0: "negative"
+      elif x > 0: "positive"
+      else: "zero"
+
   proc toString(x: bool): string =
-    if x: result = "true"
-    else: result = "false"
+    result =
+      if x: "yep"
+      else: "nope"
 
-  echo toString(13)   # calls the toString(x: int) proc
-  echo toString(true) # calls the toString(x: bool) proc
+  assert toString(13) == "positive" # calls the toString(x: int) proc
+  assert toString(true) == "yep"    # calls the toString(x: bool) proc
 
 (Note that ``toString`` is usually the `$ <dollars.html>`_ operator in
 Nim.) The compiler chooses the most appropriate proc for the ``toString``
'parallel'' href='/ahoang/Nim/commit/tests/system/tsysspawn.nim?h=devel&id=6195dbe491ccd864c5dcb59f87826291ac1f1ff4'>6195dbe49 ^
a822d0bf0 ^

6195dbe49 ^
a822d0bf0 ^








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31