A tour of Xo
Twelve short steps through the language. Every program on these pages is checked, run, and tested with the current toolchain before the site is published, and every error message shown is the compiler’s real output.
If you know Go, most of Xo will look familiar. The differences are where Go lets a bug compile: ignored errors, nil, missing cases, data races, leaked goroutines, and code that reaches the network or the disk without saying so.
- Basics: Bindings, functions, string interpolation, and expressions.
- Structs, enums, and newtypes: Structs, sum types, derived behavior, type aliases, and newtypes.
- Lists, maps, and sets: Immutable persistent collections, higher order methods, and safe map reads.
- No nil: optionals: T? instead of nil, if let, ??, and ? on optionals.
- Errors you have to handle: Result types, ?, error enums with from variants, and why ignoring an error does not compile.
- Pattern matching: Exhaustive match, ranges, alternatives, list shapes, tuples, and is.
- Values and mutation: Value semantics, var receivers, updating collections in place, Mutex and Atomic.
- Effects and capabilities: uses clauses, capability values passed from main, and fake capabilities in tests.
- Structured concurrency: Scopes, tasks, await, channels, and cancellation without ctx plumbing.
- Contracts and tests: requires, ensures, invariants, test blocks, property tests, and contract fuzzing.
- A small web service: std/http routing, JSON, typed path parameters, errors that map to status codes, and in process tests.
- Using Go packages: use go to call any Go package, with bindings generated automatically.