The Ξ (Xi) Programming Language
A statically-typed, ahead-of-time compiled language that makes dependency injection, function intent, and refined types first-class - compiled to native binaries through C, and self-hosting.
Xi is self-hosting - its compiler is written in Xi and compiles its own source to a byte-identical fixpoint. The only non-Xi code is a small C runtime (the equivalent of a language's libc/libcore). You don't need any of that to write Xi - install the toolchain and go.
Install
On macOS (Apple Silicon + Intel) and Linux, install with Homebrew:
brew install code-by-sia/xi/xi
Or grab a prebuilt tarball from the
releases page and put its bin/ on
your PATH. Either way you get xc (compiler) and xi (run tool + REPL); you
just need a C compiler (cc) on PATH. Full steps:
Getting started.
Highlights
- Refined types -
type Age = Number where value >= 0 and value <= 130, checked at construction. - Eight function kinds -
mapper,projector,predicate,consumer,producer,reducer,creator,action: intent is syntactic. - Dependency injection in the language -
deps { ... },module { bind ... },App.resolve(Interface), conditionalwhenbindings,singleton/transient. where-guarded overloading - multiple functions with one name, selected by a guard.- Decision tables, interrupts, atoms, machines & events - business rules,
resumable conditions, active-state stores, finite state machines, and
publish/subscribe with the
listenerkind, all as language features. - Error handling -
T!result types,ok/err, and?propagation. - Serialization - a built-in
std/jsonlibrary. - Query - reified query chains:
query.from<User>("users") .filter { it.age >= 18 }.collect(db)compiles to a typed plan a provider runs in memory or renders to SQL. - Repository -
std/datagenericRepository/CrudRepositoryinterfaces bind to any provider: composable reads, provider-backed writes, and overridable entity ↔ model mapping. - Native output - compiles to a standalone binary via C; no VM, no GC.
A taste
import "std/log.xi"
type Age = Number where value >= 0 and value <= 130
type User = { name: String, age: Age }
predicate isAdult(u: User) { return u.age >= 18 }
mapper describe(u: User) -> String {
return u.name + " (" + u.age + ")"
}
async entry (logger: Logger) main(args: String[]) {
let u = User { name: "Ada", age: 36 }
if isAdult(u) { logger.info(describe(u)) }
}
module App {}
$ xc greeting.xi && ./build/greeting
Where to go next
The docs are ordered as a path. If you are new, read down this list; each page assumes the ones above it.
| # | Read | To learn |
|---|---|---|
| 1 | Getting started · CLI | install the toolchain, compile and run a file |
| 2 | Language guide | types, refined types, the function kinds, interfaces, generics |
| 3 | Error handling · Decision tables | T! results, ? propagation, business rules as tables |
| 4 | Dependency injection | deps, module, binds and scopes - the heart of how Xi apps are wired |
| 5 | Multi-file projects · Config · Testing | modules, imports, typed config, xt |
| 6 | Atoms · Machines · Interrupts · Events | state that accumulates, state machines, resumable conditions, pub/sub |
| 7 | Threading · Memory | share-nothing threads, channels, how allocation works |
| 8 | Standard library | every module, with links to the guides below |
The standard library
| Module | Guide | What it gives you |
|---|---|---|
std/collections | Collections | List, Set, Map, Stack, sequences, ranges |
std/json, yaml, xml | Serialization | a Json tree, derived codecs, as Json |
std/query, std/sql | Query | reified query chains that a provider runs or renders to SQL |
std/data | Repository | Repository / CrudRepository over any provider |
std/web | Web | a REST framework: controllers, routing, HTTPS/HTTP-2 |
std/events | Events | typed publish/subscribe with listener |
std/monitoring | Monitoring | health and metrics, decoupled from what it watches |
std/thread | Threading | threads and channels |
| plus | stdlib reference | math, text, bytes, crypto, fs, net, http, time, io, … |
Interop lives in FFI (calling C) and WebAssembly.
Showcase
See Xi in a real application: eXstream is a music-streaming service whose backend is a set of Xi microservices (auth, file storage, playlist) behind an API gateway, with a React front end and Docker deployment - an end-to-end example of modules, dependency injection, the web framework, and JWT auth.
Ready? Head to Getting started.