Skip to main content

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.

Get started → GitHub

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), conditional when bindings, 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 listener kind, all as language features.
  • Error handling - T! result types, ok/err, and ? propagation.
  • Serialization - a built-in std/json library.
  • 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/data generic Repository / CrudRepository interfaces 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.

#ReadTo learn
1Getting started · CLIinstall the toolchain, compile and run a file
2Language guidetypes, refined types, the function kinds, interfaces, generics
3Error handling · Decision tablesT! results, ? propagation, business rules as tables
4Dependency injectiondeps, module, binds and scopes - the heart of how Xi apps are wired
5Multi-file projects · Config · Testingmodules, imports, typed config, xt
6Atoms · Machines · Interrupts · Eventsstate that accumulates, state machines, resumable conditions, pub/sub
7Threading · Memoryshare-nothing threads, channels, how allocation works
8Standard libraryevery module, with links to the guides below

The standard library

ModuleGuideWhat it gives you
std/collectionsCollectionsList, Set, Map, Stack, sequences, ranges
std/json, yaml, xmlSerializationa Json tree, derived codecs, as Json
std/query, std/sqlQueryreified query chains that a provider runs or renders to SQL
std/dataRepositoryRepository / CrudRepository over any provider
std/webWeba REST framework: controllers, routing, HTTPS/HTTP-2
std/eventsEventstyped publish/subscribe with listener
std/monitoringMonitoringhealth and metrics, decoupled from what it watches
std/threadThreadingthreads and channels
plusstdlib referencemath, 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.