Goose Lang 101: One Array, One Slice, One Function
Part 3 of Goose lang and Flisk.sh 101. Stay in ~/src/goose-flisk-101 . Run every file with goose file.goose before you build it. Goose has no heap allocator and no garbage collector. Dynamic values live on data stacks the compiler assigns. Growth bumps a pointer. Scope exit moves that pointer back. You do not write the stack. You do choose the array spelling, because that spelling is the…
This Goose language tutorial covers the basics of arrays, slices, and functions in Goose lang. The Goose language does not have a heap allocator or garbage collector, and values live on data stacks assigned by the compiler. Growth bumps a pointer, and scope exit moves that pointer back. The array spelling chosen is the contract, and in week one, the grow-only array T[..] is used.
References into the array stay valid across push operations, which is different from Vec T. The total function takes an array or slice and returns the sum of its elements without copying the elements. The main function demonstrates the use of the grow array, printing its contents, the total, and the total of a slice of it. Goose arrays are slices, a reference plus a count, and can be accessed using ^k for end-based counting.
Variables can only be reassigned with let, while var can be reassigned. Types usually infer, and there is no separate string type in Goose. The divide function demonstrates Euclidean division, returning both the quotient and a boolean indicating success. The three rules mentioned that can be confusing on day one are arithmetic using the operands' width, implicit type widening for narrow types, and the requirement to use as or as! for narrowing.
Growable values are not copied by assignment and bind a reference instead. The tutorial advises ignoring relative references, reusable pools, returning errors from load, threads, and external functions until the official tutorial. The compiler is still young, lacking namespace privacy, labeled break, and whole-program compilation.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.