Learn/Quick Start

Quick Start

Get Rey installed and write your first program in under 5 minutes.

~5 minBeginner
1

Install Rey

Download the latest release for your platform or install via the install script:

Terminal
$ curl -fsSL https://get.reylang.dev | sh
Downloading rey v0.2.0 for macOS arm64...
Installed to /usr/local/bin/rey

Or download a pre-built binary from the Download page. Verify your installation:

Terminal
$ rey --version
rey 0.2.0 (self-hosted, LLVM backend)
2

Hello, World!

Create a file called hello.rey:

hello.rey
func main(): Void {
    println("Hello, World!");
}

Compile and run it:

Terminal
$ rey build hello.rey
Compiled hello → ./hello
$ ./hello
Hello, World!
It works!

You compiled a Rey program to a native binary. No runtime, no VM — just machine code.

3

Variables & Type Inference

Declare variables with var. The type is inferred from the value — you don't need to annotate:

types.rey
func main(): Void {
    var name = "Alice";        "color:#637099">// inferred: String
    var age = 30;              "color:#637099">// inferred: Int
    var score = 98.6;          "color:#637099">// inferred: Float

    "color:#637099">// explicit annotations — enforced at compile time
    var count: Int = 0;
    var greeting: String = "Hey, " + name;

    println(greeting);
    println(age);
}

Once a variable is declared, its type is fixed. Assigning a value of the wrong type is a compile error.

4

Functions

Functions are declared with func. Parameters and return types are always annotated:

functions.rey
func add(a: Int, b: Int): Int {
    return a + b;
}

func greet(name: String): String {
    return "Hello, " + name + "!";
}

func main(): Void {
    println(greet("Rey"));           "color:#637099">// Hello, Rey!
    println(add(3, 4));              "color:#637099">// 7

    "color:#637099">// lambdas work too
    var double = (x: Int) => x * 2;
    println(double(5));              "color:#637099">// 10
}
5

Structs & Enums

Group data with structs and model variants with enums:

data.rey
struct Point {
    pub x: Int,
    pub y: Int,
}

enum Direction {
    North,
    South,
    East,
    West,
}

func move(p: Point, dir: Direction): Point {
    match dir {
        Direction.North => return Point { x: p.x, y: p.y + 1 },
        Direction.South => return Point { x: p.x, y: p.y - 1 },
        Direction.East  => return Point { x: p.x + 1, y: p.y },
        Direction.West  => return Point { x: p.x - 1, y: p.y },
    }
}

func main(): Void {
    var pos = Point { x: 0, y: 0 };
    pos = move(pos, Direction.North);
    println(pos.y);  "color:#637099">// 1
}
6

Collections

Rey has built-in Vec and HashMap with functional methods:

collections.rey
func main(): Void {
    var nums = [1, 2, 3, 4, 5];

    "color:#637099">// map, filter, fold
    var doubled = nums.map((x) => x * 2);
    var evens = nums.filter((x) => x % 2 == 0);
    var sum = nums.fold(0, (acc, x) => acc + x);

    println(doubled.join(", "));   "color:#637099">// 2, 4, 6, 8, 10
    println(evens.join(", "));     "color:#637099">// 2, 4
    println(sum);                  "color:#637099">// 15

    "color:#637099">// HashMap
    var scores = HashMap.new();
    scores.set("Alice", 95);
    scores.set("Bob", 87);
    println(scores.get("Alice"));  "color:#637099">// 95
}

What's next?