Files
corelang/examples/arrays_and_slices.kl
2022-07-28 13:20:51 +02:00

28 lines
748 B
Plaintext

/*
Static arrays are exactly like c arrays, difference is
we can easily then get a slice of that array.
Slices are static arrays + length, they simplify array handling.
This allows us to pass an array into a function easily, then that function
can still access that length information easily.
Passing a pointer to array + length is a common pattern in C. So it would
be nice if handling of that was simplified.
*/
main :: (): int
static_array: [8]int
// We can get size of array using length_of builtin
#assert(length_of(static_array) == 8)
element: int = static_array[0]
assert(static_array[1] == 0)
assert(element == 0)
// Variables are zeroed by default
// assert(static_array[7] == 0)
// for static_array
// it = 1