Documentation menu

Core Language

Structs

A dict works for loose data. A struct is for when a group of fields has a name and, usually, behavior that goes with it — a Point, an Enemy, a Card. Fields have no types, so a struct is really a named, checked shape plus methods, not a class in the C#/Java sense.

New to coding?

Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.

1

Declare fields, then a method

struct Name { field, field } declares the shape. Methods live outside the struct, written as fn Type.method(self, ...) — self is the instance the method was called on, same idea as most languages that spell it out instead of hiding it.

Try this code
struct Point { x, y }
fn Point.dist(self, other) {
    return dist(self.x, self.y, other.x, other.y);
}
2

Make one, read and write its fields

Build an instance with Name { field: value, ... } — every field must be given a value, in any order. Dot access reads and writes fields directly; there is no separate getter/setter step.

Try this code
p1 = Point { x: 0, y: 0 };
p2 = Point { x: 3, y: 4 };
print p1.dist(p2);   # 5

p1.x = 10;           # fields are read/write
print type(p1);      # "Point"

type(instance) returns the struct's name, so error messages and debugging output say Point instead of dict.

3

What structs do not have

No inheritance, no composition, no private fields, and no constructor beyond the Name { field: value } literal itself. This is deliberate — MAKO waits for real demand before adding inheritance rather than guessing at a design upfront.