diff --git a/Nimrod-for-C-programmers.md b/Nimrod-for-C-programmers.md new file mode 100644 index 0000000..486087c --- /dev/null +++ b/Nimrod-for-C-programmers.md @@ -0,0 +1,65 @@ +(Work in progress) + +This is a guide for people with experience in C or a similar language. The general tutorials can be found here: + +http://nimrod-lang.org/tut1.html +http://nimrod-lang.org/tut2.html + +The manual provides a more or less complete overview of the language: + +http://nimrod-lang.org/manual.html + +### Structs - Tuples and Objects + +Tuples and Objects in Nimrod are kind of like structs in C, but not really. + +### Interfacing C and Nimrod + +See [Foreign Function Interface](http://nimrod-lang.org/manual.html#foreign-function-interface) + +### Cheat Sheet +Note: Code examples are not exactly one-to-one, there may be subtle differences in the semantics. See comments. + + + + + + + + + + + + + + + + +
CNimrodComment
+```C +int x = foobar() ? 42 : 0; +``` + +```Nimrod +var x = if foobar(): 42 else: 0 +``` + +If-statements return the value of the expression they evaluate to, so Nimrod doesn't need a ternary operator. +
+```C +void foobar(person_t *a) { + person_t b; + b = *a; + b.name = "Bob"; + *a = b; +} +``` + +```Nimrod +proc foobar(a: ref TPerson) = + var b: TPerson + b = a[] + b.name = "Bob" + a[] = b +``` +Dereference. In C, only the pointer to the strings in the struct is copied. In Nimrod, the string is also copied, but refs are not deep-copied.
\ No newline at end of file