Updated Nimrod for C programmers (markdown)

This commit is contained in:
Audun Wilhelmsen 2013-12-26 15:21:33 -08:00
parent 3565b10410
commit 5282b3ad57
1 changed files with 4 additions and 2 deletions

View File

@ -34,7 +34,8 @@ The other important thing to know is that while C uses a separate language to do
In C an array is more or less syntactic sugar for pointers. In Nimrod, arrays are much more strict and safe to use. They are pass-by-value (meaning they're copied at assignment). When passing an array to a proc in Nimrod, the argument is a read-only reference, meaning it can't be assigned to. Take the following example: In C an array is more or less syntactic sugar for pointers. In Nimrod, arrays are much more strict and safe to use. They are pass-by-value (meaning they're copied at assignment). When passing an array to a proc in Nimrod, the argument is a read-only reference, meaning it can't be assigned to. Take the following example:
**C:** **C:**
```c
```C
void foobar(int z[4]) { void foobar(int z[4]) {
z[5] = 5; z[5] = 5;
printf("%d\n",z[5]); printf("%d\n",z[5]);
@ -48,7 +49,8 @@ int main() {
``` ```
**Nimrod:** **Nimrod:**
```nimrod
```Nimrod
proc foobar(z: array[0..3, int]) = proc foobar(z: array[0..3, int]) =
z[5] = 5 # Error: Cannot assign to z z[5] = 5 # Error: Cannot assign to z
echo z[5] # Error: Index out of bounds. echo z[5] # Error: Index out of bounds.