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.
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.rexfunc main() {
print("Hello, Rex!")
}Four keywords do most of the work: var, func, for,match. No parentheses around conditions, and types are inferred.
func main() {
print("Hello, Rex!")
}One entry point, no semicolons, no ceremony.
enum Shape {
Circle(r: float)
Rect(w, h: float)
}
func area(s: Shape): float {
return match s {
Circle(r) => 3.14 * r * r
Rect(w, h) => w * h
}
}Variants carry data. match has to cover every case, so a forgotten one can’t slip through.
func parse_age(text: string): (int, error) {
// …
if err != nil { return 0, err }
// …
}A function that can fail says so in its signature, and returns the error next to the value. A value that may be missing is T?.
var counts: map[string, int] = {}
for word in "the cat and the hat".split(" ") { counts[word] += 1 }Types are inferred where you’d expect and spelled out where they help.
// straight from a C header
import "raylib.h"
// after: rex add git.joji.li/joji/json
import jsonRex reads C headers directly. Packages come from git and get pinned in rex.lock.
Your code becomes C, then cc builds it. rex emit-c prints the C Rex wrote for you, so nothing is hidden.
You never manage memory by hand. For the few times you need a graph or a cache, there’sshared and weak.
Fallible functions return (T, error). A value that may be missing isT?.
enum Shape {
Circle(r: float)
Rect(w, h: float)
}Exhaustive match keeps you honest.
import "raylib.h"Rex reads the header, links the library, and builds next to your own .c and.cpp files.
Add one, import it, and let rex.lock pin the version.
rex add git.joji.li/joji/json
import jsonThe compiler, formatter, language server and package manager all ship inside rex. Nothing else to install.
$ rex run hello.rex$ rex build file.rex -o out$ rex check file.rex$ rex emit-c file.rex$ rex fmt [--check] path…$ rex lsp$ rex header file.h [word]$ rex add <git-url>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.
$ git clone https://git.joji.li/joji/rexlang
$ cd rexlang$ cargo build --release
$ cp target/release/rex ~/.local/bin/func main() {
print("Hello, Rex!")
}$ rex run hello.rexWant more than hello? Start the course or keep thecheatsheet open.