Merge pull request #2936 from alexamy/alexamy-patch-1

Tutorial Part I update
This commit is contained in:
Andreas Rumpf
2015-06-16 20:46:55 +02:00

View File

@@ -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.