Skip to content

Examples

Andrew Matthews edited this page Aug 14, 2025 · 3 revisions

Examples

Short, copyable snippets that mirror what’s covered by tests today.

Hello, world (via return)

  • main(): string { return "hello"; }

Basic math

  • main(): int { return 3 + 7; }
  • main(): float { return 3 / 2; } // division promotes to float

Branching

  • foo(i: int): string {
  • if (i <= 15) { return "child"; }
  • else { return "adult"; }
  • }

Variables

  • a: int;
  • a: int = 5;
  • a = a * 6;

Overloads

  • foo(i: int): string { return "child"; }
  • foo(s: string): string { return s; }

Lists

  • xs: int[] = [1, 2, 3];
  • ys: int[] = [x * 2 for x in xs];

While loop

  • while (i < 10) {
  • i = i + 1;
  • }

Properties

  • p.Weight = p.Weight + 1;

Recursive destructuring (beyond C#)

calculate_bmi(p: Person {
    name: Name,
    vitals: Vitals{
        age: Age,
        height: Height,
        weight: Weight
        }
    }) : float {
    return weight / (height * height);
}

See Recursive Destructuring for more.

Note: Syntax is under active development; consult Language Guide and repository tests for latest details.

Clone this wiki locally