Looks like Go.
Runs like C.

Rex is a small, fast language that compiles to C and lands as a native program. You never write anything low-level.

$ rex run hello.rex
rex run
func main() {
    print("Hello, Rex!")
}

Reads like Go.
Nothing to decode.

Four keywords do most of the work: var, func, for,match. No parentheses around conditions, and types are inferred.

hello.rex
func main() {
    print("Hello, Rex!")
}

One entry point, no semicolons, no ceremony.

What’s in the egg

Compiles to C. Ships as native.

Your code becomes C, then cc builds it. rex emit-c prints the C Rex wrote for you, so nothing is hidden.

No GC.
No pointers.

You never manage memory by hand. For the few times you need a graph or a cache, there’sshared and weak.

Errors are values

Fallible functions return (T, error). A value that may be missing isT?.

Enums carry data

enum Shape {
    Circle(r: float)
    Rect(w, h: float)
}

Exhaustive match keeps you honest.

Friendly with C and C++

import "raylib.h"

Rex reads the header, links the library, and builds next to your own .c and.cpp files.

Packages come from git

Add one, import it, and let rex.lock pin the version.

rex add git.joji.li/joji/json
import json

One binary.
The whole toolbox.

The compiler, formatter, language server and package manager all ship inside rex. Nothing else to install.

$ rex run hello.rex
Compile and run a file.
$ rex build file.rex -o out
Produce a reusable executable.
$ rex check file.rex
Look for errors without building.
$ rex emit-c file.rex
Print the C that Rex generates.
$ rex fmt [--check] path…
Format your code.
$ rex lsp
Start the language server.
$ rex header file.h [word]
Show what Rex can use from a C header.
$ rex add <git-url>
Add a package, pinned in rex.lock.

Hatch your first program

You need a Rust toolchain to build the compiler and a C compiler (gcc orclang, as cc) to build programs. Rex has no dependencies of its own.

  1. Get the source

    $ git clone https://git.joji.li/joji/rexlang
    $ cd rexlang
  2. Build the compiler and put it on your PATH

    $ cargo build --release
    $ cp target/release/rex ~/.local/bin/
  3. Write a file and run it

    hello.rex
    func main() {
        print("Hello, Rex!")
    }
    $ rex run hello.rex

Want more than hello? Start the course or keep thecheatsheet open.