summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2015-06-16 20:46:55 +0200
committerAndreas Rumpf <rumpf_a@web.de>2015-06-16 20:46:55 +0200
commitddb62747e88eec3eead7f79e351f7910e197dd44 (patch)
tree29780843e96de3ae0c076ab200d08ceaab424f50 /doc
parentad1ac7656733fb8320fa4b144f40147b291b50f3 (diff)
parent77b51df09c6e853e4e852b8676ea0c2666b7683b (diff)
downloadNim-ddb62747e88eec3eead7f79e351f7910e197dd44.tar.gz
Merge pull request #2936 from alexamy/alexamy-patch-1
Tutorial Part I update
Diffstat (limited to 'doc')
-rw-r--r--doc/tut1.txt15
1 files changed, 12 insertions, 3 deletions
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 1fa495054..500480cf0 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -757,16 +757,25 @@ However, this cannot be done for mutually recursive procedures:
   # forward declaration:
   proc even(n: int): bool
 
-  proc odd(n: int): bool =
+proc even(n: int): bool
+
+proc odd(n: int): bool =
+  assert(n >= 0) # makes sure we don't run into negative recursion
+  if n == 0: false
+  else:
     n == 1 or even(n-1)
 
-  proc even(n: int): bool =
+proc even(n: int): bool =
+  assert(n >= 0) # makes sure we don't run into negative recursion
+  if n == 1: false
+  else:
     n == 0 or odd(n-1)
 
 Here ``odd`` depends on ``even`` and vice versa. Thus ``even`` needs to be
 introduced to the compiler before it is completely defined. The syntax for
 such a forward declaration is simple: just omit the ``=`` and the
-procedure's body.
+procedure's body. The ``assert`` just adds border conditions, and will be 
+covered later in `Modules`_ section.
 
 Later versions of the language will weaken the requirements for forward
 declarations.