Structs

Define custom data types with named fields.

Definition

struct Point {
    x;
    y;
}

Creating Instances

var origin = Point(0, 0);
var target = Point(10, 20);

Field Access

print(target.x);   // 10
print(target.y);   // 20

Field Modification

target.x = 50;
target.y = 100;
print("New: (" + target.x + ", " + target.y + ")");

Factory Functions

struct Product {
    id;
    name;
    price;
}

var nextId = 0;

function createProduct(name, price) {
    nextId = nextId + 1;
    return Product(nextId, name, price);
}

var laptop = createProduct("Laptop", 999);
print(laptop.id);     // 1
print(laptop.name);   // Laptop

Passing to Functions

function formatProduct(p) {
    return p.name + " - $" + p.price;
}

print(formatProduct(laptop));  // Laptop - $999