Documentation channel: current development main at compiler checkpoint 1d7e15e. The latest tagged release is v0.0.3; pages identify APIs that are not yet released.
Structs
Structs group typed fields and methods. Methods may be defined inline or separately with Struct::method.
Define and construct
struct User {
int id;
string name;
}
user := User {
id: 1,
name: "Ada"
};
Inline methods
struct Counter {
int value;
function increment() -> void {
value++;
}
}
Out-of-struct definitions
struct User {
string name;
function label() -> string;
}
function User::label() -> string {
return name;
}
Abstract contracts and inheritance
A struct with required methods that have no implementation cannot be instantiated. Derived structs can satisfy those contracts. Strut permits one data-bearing base plus additional contract-style bases.
struct Printable {
function print_to(ostream& out) -> void;
}
struct User : Printable {
string name;
function print_to(ostream& out) -> void {
out << name;
}
}
