From 8c8a8ccd619744275f252477764a7036f28d210b Mon Sep 17 00:00:00 2001 From: Daniil Yarancev <21169548+Yardanico@users.noreply.github.com> Date: Mon, 16 Oct 2017 15:39:39 +0300 Subject: [PATCH] Updated Nim for C programmers (markdown) --- Nim-for-C-programmers.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Nim-for-C-programmers.md b/Nim-for-C-programmers.md index 17f0aa9..ffafe4c 100644 --- a/Nim-for-C-programmers.md +++ b/Nim-for-C-programmers.md @@ -29,7 +29,7 @@ Types | Static | Static Dependent types | No | Partial support Generics | No (Templates w/ C++) | 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 Bounds-checking | No | Yes Type inference | No (some w/ C++11) | Yes (extensive support) @@ -71,7 +71,7 @@ int main() { **Nim:** -```Nimrod +```nim proc foobar(z: array[0..3, int]) = z[5] = 5 # Error: Cannot assign to z 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_. -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 @@ -302,8 +302,7 @@ proc bar(): int = proc baz(x: int): int = x*2 -proc foobar(x: var int): - int = +proc foobar(x: var int): int = inc(x) result = x*2 @@ -340,8 +339,8 @@ void foobar(person_t *a) {
-proc foobar(a: ref TPerson) =
-  var b: TPerson
+proc foobar(a: ref Person) =
+  var b: Person
   b = a[]
   b.name = "Bob"
   a[] = b
@@ -367,7 +366,7 @@ printf("%d, %d, %p\n", x, y, p);
 
 
 
-var d: float = 3.1415926
+var d = 3.1415926
 var i = d.int
 d = i.float
 echo i, " ",d