SultanC
  1. Home
  2. Examples
  3. Data

Nested records and access to their fields

data/records.sn
type Point = { x: int, y: int };
type Rectangle = { start: Point, end: Point };

def main(): int {
    let start: Point = { x: 10, y: 11 };
    let end: Point = { x: 12, y: 9 };
    let rectangle: Rectangle = { start: start, end: end };
    return rectangle.start.x + rectangle.start.y + rectangle.end.x + rectangle.end.y;
}

Run it

With the interpreter, without compiling:

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

Or compile it to an executable:

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

Source on GitHub   All examples