Structs
Structs are named record types that group related values under named fields. Methods can be attached to any struct type using extend blocks.
Overview
A struct definition introduces a new named type with an ordered list of field names. Once defined, a struct type can be instantiated by providing values for every field in a struct literal. The resulting value is a struct instance that holds those field values and can be stored in a variable.
Individual fields are read with dot syntax (obj.field) and updated with field assignment syntax (obj.field = expr). Field assignment mutates the existing instance in place — all variables that hold a reference to the same instance see the updated value immediately.
Methods are defined separately from the struct using an extend block. Each method receives the instance it was called on as its first parameter, conventionally named self. Calling a method through dot syntax (obj.method(args)) automatically supplies the instance as self; the caller does not pass it explicitly.
Syntax
Struct Definition
struct <TypeName> {
<field>,
<field>,
...
}
<TypeName>— an identifier naming the type; registered in the global struct registry.<field>— one or more field names separated by commas. Fields have no type annotation — they hold any value at runtime.