diff --git a/content/variables.md b/content/variables.md index f3ea091..6db20d2 100644 --- a/content/variables.md +++ b/content/variables.md @@ -7,9 +7,10 @@ Nimrod supports three different types of variables, `let`, `var`, and `const`. A ``` nimrod proc getAlphabet(): string = - result = "" + var accm = "" for letter in 'a'..'z': - result.add(letter) + accm.add(letter) + return accm # Computed at compilation time const alphabet = getAlphabet() diff --git a/content/variables/result.md b/content/variables/result.md index dfc249c..dbccdaa 100644 --- a/content/variables/result.md +++ b/content/variables/result.md @@ -3,13 +3,13 @@ title: Result --- # Result -The `result` variable is a special variable that serves as an implicit return variable, which exists because the control flow semantics of the `return` statement are rarely needed. The result variable is initialized in the standard way, as if it was declared with `var result: T`. +The `result` variable is a special variable that serves as an implicit return variable, which exists because the control flow semantics of the `return` statement are rarely needed. The result variable is initialized in the standard way, as if it was declared with `var result: ReturnType`. For example, the `getAlphabet()` function could be rewritten more concisely as ``` nimrod -proc `**`(number, power: int): int = - result = 1 - for i in 1..power: - result *= number +proc getAlphabet(): string = + result = "" + for letter in 'a'..'z': + result.add(letter) ``` A possible gotcha is declaring a new variable called `result` and expecting it to have the same semantics.