Updated Nim for C programmers (markdown)
This commit is contained in:
parent
719d864ea7
commit
8c8a8ccd61
|
@ -29,7 +29,7 @@ Types | Static | Static
|
||||||
Dependent types | No | Partial support
|
Dependent types | No | Partial support
|
||||||
Generics | No (Templates w/ C++) | Yes
|
Generics | No (Templates w/ C++) | Yes
|
||||||
int8/16/32/64 types | Yes | Yes
|
int8/16/32/64 types | Yes | Yes
|
||||||
Unsigned ints | Yes (by default) | Yes (not by default)
|
Unsigned ints | Yes (by default) | Yes
|
||||||
Arrays | Yes | Yes
|
Arrays | Yes | Yes
|
||||||
Bounds-checking | No | Yes
|
Bounds-checking | No | Yes
|
||||||
Type inference | No (some w/ C++11) | Yes (extensive support)
|
Type inference | No (some w/ C++11) | Yes (extensive support)
|
||||||
|
@ -71,7 +71,7 @@ int main() {
|
||||||
|
|
||||||
**Nim:**
|
**Nim:**
|
||||||
|
|
||||||
```Nimrod
|
```nim
|
||||||
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.
|
||||||
|
@ -104,7 +104,7 @@ You can call a proc on objects with the ```anObject.foobar()```, but you can do
|
||||||
|
|
||||||
Nim does not have an implicit _this_/_self_.
|
Nim does not have an implicit _this_/_self_.
|
||||||
|
|
||||||
It is possible to implement object-orientation features from other languages (like C++,Java,etc. or Smalltalk,Obj-C,Ruby,etc.) through libraries, thanks to the extensive meta-programming features of Nim. These are at the moment mostly work-in-progress.
|
It is possible to implement object-orientation features from other languages (like C++, Java, etc. or Smalltalk, Obj-C, Ruby, etc.) through libraries, thanks to the extensive meta-programming features of Nim. These are at the moment mostly work-in-progress.
|
||||||
|
|
||||||
### Structs - Tuples and Objects
|
### Structs - Tuples and Objects
|
||||||
|
|
||||||
|
@ -302,8 +302,7 @@ proc bar(): int =
|
||||||
proc baz(x: int): int =
|
proc baz(x: int): int =
|
||||||
x*2
|
x*2
|
||||||
|
|
||||||
proc foobar(x: var int):
|
proc foobar(x: var int): int =
|
||||||
int =
|
|
||||||
inc(x)
|
inc(x)
|
||||||
result = x*2
|
result = x*2
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -340,8 +339,8 @@ void foobar(person_t *a) {
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<pre>
|
<pre>
|
||||||
proc foobar(a: ref TPerson) =
|
proc foobar(a: ref Person) =
|
||||||
var b: TPerson
|
var b: Person
|
||||||
b = a[]
|
b = a[]
|
||||||
b.name = "Bob"
|
b.name = "Bob"
|
||||||
a[] = b
|
a[] = b
|
||||||
|
@ -367,7 +366,7 @@ printf("%d, %d, %p\n", x, y, p);
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<pre>
|
<pre>
|
||||||
var d: float = 3.1415926
|
var d = 3.1415926
|
||||||
var i = d.int
|
var i = d.int
|
||||||
d = i.float
|
d = i.float
|
||||||
echo i, " ",d
|
echo i, " ",d
|
||||||
|
|
Loading…
Reference in New Issue