@@ -10,28 +10,90 @@ ShowBreadCrumbs: true
1010
1111## Types
1212
13- This is a table that hold a comparison of all fundamental types you should know about:
14-
15- | Type: | Jai |
16- | ----------------------------| -----------------|
17- | 32 bit floating | ` float32 ` |
18- | 64 bit floating | ` float64 ` |
19- | 128 bit floating | ` f128 ` |
20- | 8 bit integer signed | ` s8 ` |
21- | 8 bit integer unsigned | ` u8 ` |
22- | 16 bit integer signed | ` s16 ` |
23- | 16 bit integer unsigned | ` u16 ` |
24- | 32 bit integer signed | ` s32 ` |
25- | 32 bit integer unsigned | ` u32 ` |
26- | 64 bit integer signed | ` s64 ` |
27- | 64 bit integer unsigned | ` u64 ` |
28- | boolean | ` bool ` |
29- | character | ` todo ` |
30- | string | ` string ` |
31- | null | ` todo ` |
13+ This is a table that hold a comparison of all fundamental types you should know about compared to what they are in other languages:
14+
15+
16+ | Type: | Jai | C# | C++ (classic) | C++ (modern) |
17+ | ----------------------------| -----------------| -----------------| ---------------------------| ------------------|
18+ | 32 bit floating | ` float32 ` | `` float `` | `` float `` | - |
19+ | 64 bit floating | ` float64 ` | `` double `` | `` double `` | - |
20+ | 128 bit floating | ` f128 ` | `` decimal `` | - | - |
21+ | 8 bit integer signed | ` s8 ` | `` sbyte `` | `` char `` | `` int8_t `` |
22+ | 8 bit integer unsigned | ` u8 ` | `` byte `` | `` unsigned char `` | `` uint8_t `` |
23+ | 16 bit integer signed | ` s16 ` | `` short `` | `` short `` | `` int16_t `` |
24+ | 16 bit integer unsigned | ` u16 ` | `` ushort `` | `` unsigned short `` | `` uint16_t `` |
25+ | 32 bit integer signed | ` s32 ` | `` int `` | `` int `` | `` int32_t `` |
26+ | 32 bit integer unsigned | ` u32 ` | `` uint `` | `` unsigned int `` | `` uint32_t `` |
27+ | 64 bit integer signed | ` s64 ` | `` long `` | `` long long `` | `` int64_t `` |
28+ | 64 bit integer unsigned | ` u64 ` | `` ulong `` | `` unsigned long long `` | `` uint64_t `` |
29+ | boolean | ` bool ` | `` bool `` | `` bool `` | - |
30+ | character | ` todo ` | `` char `` | `` char `` | `` char16_t `` |
31+ | string | ` string ` | `` string `` | `` string `` | - |
32+ | null | ` todo ` | `` null `` | `` nullptr `` | - |
3233
3334Jai strings are array views over ` u8 ` and are not null-terminated.
3435
36+ ## Loops
37+
38+ ** Simple for loops:**
39+
40+ The simple format for for loops is ` for set action ` , where the ` set ` is something that supports iteration and ` action ` is a statement or a block.
41+
42+ ``` jai
43+ for 1..10 {
44+ print("Number %\n", it); // it is the iteration
45+ }
46+
47+ for i: 1..10 {
48+ print("Number %\n", i); // you can name the iteration
49+ }
50+
51+ for foods {
52+ print(" %. %\n", it_index, it); // if looping over a collection you can use it_index to get its index
53+ }
54+
55+ for i: 0..10 {
56+ for j: 0..10 {
57+ print("%, %", i, j); // you can also have a nested loop
58+ }
59+ }
60+
61+ for < i: 0..10 {
62+ print("%", i); // to do a for loop in reverse, add a < in front of the for loop
63+ }
64+
65+ array := int.[1, 2, 3, 4, 5];
66+ for * ele: array { // To iterate an array by pointer, add a * in front of the for loop.
67+ ele.* = 0; // Because you are taking a pointer to the array, you can modify the array elements.
68+ }
69+
70+
71+ for 1..10 print("Number %\n", it); // single like loops are also allowed
72+ ```
73+
74+ ** The remove statement:**
75+
76+ The remove statement is used to remove an element from a dynamic array [ ..] without needing to rewrite the entire for loop into a while loop.
77+ The remove statement assumes an unordered remove, the remove swaps the current element that is being iterated on with the last element,
78+ and then removes the last element. The remove statement happens in constant time O(1).
79+
80+ ``` jai
81+ arr: [..]int;
82+
83+ for i: 0..10 {
84+ array_add(*arr, i); // adding element
85+ }
86+
87+ for a: arr {
88+ if a == 2 {
89+ remove a; // removing element
90+ }
91+ }
92+ ```
93+
94+ ## Ternairy Operator
95+
96+
3597## References
3698
3799Jai does not have C++ references. It has value semantics by default and uses pointers when you need an address.
@@ -94,20 +156,30 @@ p: *int = arr.data; // data is the adress of the array
94156p += 1; // advance by size_of(int)
95157```
96158
97- dereference chaining in C is like this:
159+ pointers to pointers and dereference chaining in c is like this:
98160
99161``` c
100162// c
101- *p = 2 ; // single
102- (*(*(*p))) = 2 ; // chain
163+
164+ int a = 3 ;
165+ int * b = &a;
166+ int ** c = &b
167+ int *** d = &c
168+
169+ int e = int e = (*(*(*d))); // dereference in a chain
103170```
104171
105- dereference chaining in jai is like this:
172+ pointers to pointers and dereference chaining in jai is like this:
106173
107174``` jai
108175// jai
109- p.* = 2; // single
110- p.*.*.* = 2; // chain
176+
177+ a: int = 3;
178+ b: *int = *a;
179+ c: **int = *b;
180+ d: ***int = *c;
181+
182+ e: int = d.*.*.*; // dereference in a chain
111183```
112184
113185## Headers
@@ -121,7 +193,7 @@ Import a module:
121193#import "Basic";
122194```
123195
124- Load exported members of a file:
196+ Load all exported functions/structs/globals of a file, and make the available here :
125197``` jai
126198#load "my_file.jai";
127199```
0 commit comments