Add formatting css and reorganize

This commit is contained in:
flaviut 2014-05-31 21:16:18 -04:00
commit 5747e5fa90
21 changed files with 308 additions and 199 deletions

View file

@ -2,7 +2,7 @@
Nimrod supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section.
~~~ nimrod
``` nimrod
proc getAlphabet(): string =
result = ""
for letter in 'a'..'z':
@ -23,22 +23,22 @@ b.inc # This is also fine.
c.add "bar" # This will result in an error.
d.inc # As will this.
~~~
```
~~~
``` console
$ nimrod c --verbosity:2 ./assignment.nim
a20.nim(19, 0) Error: for a 'var' type a variable needs to be passed
c.add "bar" # This will result in an error.
^
~~~
```
Without `--verbosity:2` only the error will be shown.
A `const` variable's value will be evaluated at compile-time, so if you inspect the C sources, you'll see the following line:
~~~ C
``` c
STRING_LITERAL(TMP129, "abcdefghijklmnopqrstuvwxyz", 26);
~~~
```
The limitation with this is that procedures which are evaluated at compile-time cannot interface with C because there is no compile-time foreign function interface at this time.

View file

@ -2,19 +2,19 @@
The `result` variable is a special variable that serves as an implicit return variable. This is useful because in most cases, the control flow semantics of the `return` statement are unneeded. `result` is initialized with the default value for a given return type, so the following code starts as `0`, before being initialized to `number`:
~~~ nimrod
``` nimrod
proc `**`(number, power: int): int =
result = number
for i in 1..power:
result *= number
~~~
```
A possible gotcha is declaring a variable called result and expecting it to have the same semantics.
~~~ nimrod
``` nimrod
proc unexpected(): int =
var result = 5
result += 5
echo unexpected() # Prints 0, not 10
~~~
```