1 | for(int i = 10; i >= 0; i--) |
1 2 3 | for x : 0..<10 // range-based loop for x : something... // array-iterating loop? May have got the syntax wrong |
Hjortshoej
If the array size isn't a compile time constant you make a slice instead.
1 foo := new_slice(byte, bar.count+1);
FalconJonHjortshoej
If the array size isn't a compile time constant you make a slice instead.
1 foo := new_slice(byte, bar.count+1);
Looking through the compiler, I see there are two 'new's: new and new_slice. Is the new for single values, and the slice for an array? At least, that's what I gathered.
Do these need to be 'free'd in any way? I can't find a keyword in a quick search of the compiler.
1 2 3 4 | while i := 10; i >= 0; { defer i -= 1; // Rest of code } |
1 2 | [10]int // array 10 of int []int // slice of int |
1 2 3 4 5 6 7 8 9 10 11 12 13 | // #1 a := array_or_slice[1:23]; // Slice expression (similar to python or go) // #2 b := slice_ptr(ptr, 64); // Creates a slice from a pointer and a count // #3 c := new_slice(int, 64); // Allocates a new pointer of type `int` and of length `64` from the current context's allocator // #4 d: []int; // Manual construction d.data = ptr; d.count = 123; |
gingerBill
At this current time, there is no reverse iteration method. However, this new for loop hasn't been demonstrated yet so I'd wait until then to understand the entirety of it.
To emulate a C-like for loop, you could do something like this (this isn't exactly the same though).
1 2 3 4 while i := 10; i >= 0; { defer i -= 1; // Rest of code }
---
As for casting, you can cast between slices of bytes ([]byte) and strings (string) with whatever the casting syntax of that version you are using (I've changed it in the current build which is not release yet).
---
The slice of an array must be known at compile time. If you want a "runtime"-like array, what you want is a slice.
1 2 [10]int // array 10 of int []int // slice of int
A slice is just a pointer and a count, and as such, can be used as sort of "array reference".
If you need to generate a slice from data, there are 4 main methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 // #1 a := array_or_slice[1:23]; // Slice expression (similar to python or go) // #2 b := slice_ptr(ptr, 64); // Creates a slice from a pointer and a count // #3 c := new_slice(int, 64); // Allocates a new pointer of type `int` and of length `64` from the current context's allocator // #4 d: []int; // Manual construction d.data = ptr; d.count = 123;
---
n.m. my compiler's design isn't very "typical" for a compiler but it works for me.