...
This commit is contained in:
23
specs.md
23
specs.md
@@ -182,6 +182,12 @@ Fixed-size arrays with element type and length.
|
||||
```sx
|
||||
buffer : [5]f32 = .[0, 2, 3.5, 4, 0];
|
||||
val := buffer[2]; // 3.5
|
||||
buffer.len // 5 (compile-time constant, s32)
|
||||
```
|
||||
|
||||
Arrays can also be constructed programmatically with the `Array` builtin:
|
||||
```sx
|
||||
MyArr :: Array(5, s32); // equivalent to [5]s32
|
||||
```
|
||||
|
||||
### Slice Types
|
||||
@@ -200,6 +206,23 @@ items.ptr // raw pointer
|
||||
|
||||
Slices support generic type parameters: `[]$T` introduces type parameter `T` inferred from the element type of the argument (array or slice).
|
||||
|
||||
### Subslicing
|
||||
Arrays, slices, and strings support subslice syntax to create zero-copy views:
|
||||
```sx
|
||||
arr : [5]s32 = .[3, 1, 4, 1, 5];
|
||||
sub := arr[1..4]; // []s32 → [1, 4, 1]
|
||||
head := arr[..3]; // []s32 → [3, 1, 4]
|
||||
tail := arr[2..]; // []s32 → [4, 1, 5]
|
||||
|
||||
msg := "hello world";
|
||||
word := msg[6..11]; // string → "world"
|
||||
```
|
||||
- `expr[start..end]` — elements from `start` (inclusive) to `end` (exclusive)
|
||||
- `expr[start..]` — elements from `start` to end
|
||||
- `expr[..end]` — elements from beginning to `end`
|
||||
- Result type: `[]T` for arrays/slices, `string` for strings
|
||||
- No memory allocation — the result points into the original backing storage
|
||||
|
||||
### Vector Types (SIMD)
|
||||
LLVM SIMD vectors, parameterized by length and element type.
|
||||
```sx
|
||||
|
||||
Reference in New Issue
Block a user