Learn Rex

Short chapters that teach the language from zero. Read them in order, or jump to the cheatsheet when you just need to look something up.

Start

The language

Real programs

Reference

How to read the examples

Every rex block that has a func main is a complete program you can save and run. The block right after it (marked text) shows what it prints.

```rex
func main() {
    print("hello")
}
```
```text
hello
```

The four ideas behind Rex

  1. Values. var b = a makes a real copy. Change b and a stays the same. There are no hidden aliases, which makes programs easy to reason about.
  2. The compiler infers. You don’t write mut, lifetimes or &. A method that changes its struct is detected automatically; a parameter that is only read is passed without a copy.
  3. Errors are values. Functions return (value, error) and you pass problems up with ?. Missing values are T? and the compiler makes you check for nil.
  4. Sharing is explicit. When you really want one value with several owners, you write shared. Everything else has exactly one owner and is freed at the end of its block.