XU XUv0.8.8
中文

Docs / Tutorial

07 · Arrays and strings

Dynamic arrays with push. String slices s[a:b] copy the half-open range [a, b). Bounds may be omitted: s[a:], s[:b], s[:]. Interpolation: "hi $name".

Source

@main

fn main() int {
    mut nums := [1, 2, 3]
    nums.push(4)
    println(nums.len)
    for n in nums {
        println(n)
    }

    name := "Ada"
    println("hi $name")
    s := "hello"
    println(s.len)
    println(s[1:4])
    << 0
}

Build (from the language repo root; swap the binary for your platform):

xu run examples/07_arrays_strings/main.xu
# or: xu build examples/07_arrays_strings/main.xu
# default artifact is ./main on mac/linux, ./main.exe on Windows

Run from the separate examples repository root; source files live under examples/.