SultanC
  1. Home
  2. Examples
  3. Data

Tuples group values without naming a record; `match` takes them apart

data/tuples.sn
// Tuples group values without naming a record; `match` takes them apart.
import std.io.println;
import std.text.number;

def area(size: (int, int)): int {
    match size with
    | (width, height) -> { return width * height; };
}

def main(): int {
    let point: (int, int) = (3, 4);
    match point with
    | (x, y) -> { println(int_to_text(x * x + y * y)); };
    let size: (int, int) = (6, 7);
    println(int_to_text(area(size)));
    let labeled: (string, bool) = ("ready", true);
    match labeled with
    | (label, flag) -> { if (flag) { println(label); }; };
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/data/tuples.sn

Or compile it to an executable:

./build/sultanc examples/en/data/tuples.sn -o build/example && ./build/example

Source on GitHub   All examples