⚠️ Early & ExperimentalTutorialRey v0.3.1Capybara v0.1.1

Quick Start Guide

Install Rey and write, compile, and run your first native machine binary in under five minutes using Capybara.

1

Install Capybara and Rey

Install Capybara (which bundles the latest Rey v0.3.1 compiler) via our official GitHub raw script:

$ curl -fsSL https://raw.githubusercontent.com/rey-language/capybara/main/install.sh | sh
Downloading capybara and bundling rey v0.3.1...
✓ Installed capy and rey into ~/.capy/bin

Verify your toolchain and environment:

$ capy doctor
✓ Capy: v0.1.1
✓ Rey Compiler: v0.3.1 (native LLVM)
2

Create and Run a Project

Use Capybara to initialize a new Rey application:

$ capy init --name hello
Created new Rey project "hello"
$ cd hello && capy run
Hello, World!

Open src/main.rey. Notice the clean syntax with mandatory semicolons and type declarations:

src/main.rey
rey v0.3.1
func main(): void {
    var audience: string = "World";
    println("Hello, {audience}!");
}
3

Variables, Inferred Types & Null Safety

Use var for mutable bindings and const for constants. Types can be explicitly typed or inferred. Nullable types use T?:

variables.rey
rey v0.3.1
func main(): void {
    var name = "Alice";        // inferred: string
    var count = 42;            // inferred: int
    var pi: float = 3.14159;   // explicit float
    var maybeScore: int? = null;

    if maybeScore != null {
        println("Score exists: " + maybeScore.toString());
    } else {
        println("No score recorded yet for {name}.");
    }
}
4

Functions & Higher-Order Lambdas

Functions are declared with func. First-class closures capture their environment smoothly:

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

func main(): void {
    println("3 + 4 = " + add(3, 4).toString());

    var nums = [1, 2, 3, 4, 5];
    var doubled = nums.map((x: int) => x * 2);
    println("Doubled: " + doubled.join(", "));
}
5

Structs, Enums & Pattern Matching

Model domain logic with structs and algebraic enums. Match arms are checked for exhaustiveness:

geometry.rey
rey v0.3.1
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 p = Point { x: 10, y: 20 };
    var next = move(p, Direction::North);
    println("New position: ({next.x}, {next.y})");
}

Ready to explore more?

Try code live directly in your browser or explore the complete syntax specification.