Updated Nimrod for C programmers (markdown)
This commit is contained in:
parent
1b7896de82
commit
f8c459f21b
|
@ -25,7 +25,9 @@ http://nimrod-lang.org/manual.html
|
|||
|
||||
### Philosophy
|
||||
|
||||
The key to understanding Nimrod is that Nimrod was designed to be as fast as C, but to be much safer. Many of the design-decisions are based on making it harder to shoot yourself in the foot. The other important thing to know is that while C uses a separate language to do meta-programming (the preprocessor), Nimrod meta-programming is done with the Nimrod language itself. That means that most Nimrod code can be executed at compile time, and Nimrod's ability to generate Nimrod-code at compile time is much more sophisticated.
|
||||
The key to understanding Nimrod is that Nimrod was designed to be as fast as C, but to be much safer. Many of the design-decisions are based on making it harder to shoot yourself in the foot. For example, in C you are required to use a pointer for most of your everyday programming needs. While Nimrod does give you pointers, Nimrod gives you other, safer tools for your everyday needs, while pointers are mostly reserved for interfacing with C and doing low-level system programming. In other words, C gives you a combined hammer and gun, while Nimrod gives you a separate gun and hammer.
|
||||
|
||||
The other important thing to know is that while C uses a separate language to do meta-programming (the preprocessor), Nimrod meta-programming is done with the Nimrod language itself. That means that most Nimrod code can be executed at compile time, and Nimrod's ability to generate Nimrod-code at compile time is much more sophisticated.
|
||||
|
||||
### Arrays
|
||||
|
||||
|
@ -62,7 +64,7 @@ In C, you can pass an ``int[3]`` to the foobar function, and the compiler will n
|
|||
|
||||
Nimrod arrays can also be indexed from any number. That is, ``z: array[1..4, int]`` is an array of int indexed from 1 to 4. Trying to access ``z[0]`` would throw an index out bounds error.
|
||||
|
||||
In C, there's nothing that keeps you from keeping a pointer to a stack-allocated array
|
||||
In C, there's nothing that stops you from keeping a pointer to a stack-allocated array after the function that declared it has returned (and the stack is invalidated). In Nimrod, this is true as well, but you are strongly discouraged from using pointers in Nimrod, and you can accomplish almost everything you'd otherwise use pointers for with normal arguments, "var" arguments, variables, and "ref".
|
||||
|
||||
### Structs - Tuples and Objects
|
||||
|
||||
|
|
Loading…
Reference in New Issue