x2c

Programming is Dead.Long Live Programming.

x2c is a language for people who love to code.

x2c is a quirky little language that makes programming fun and a bit weird. It has legitimate applications, presumably, but is more about coding for the joy of it. Some users of x2c report heightened expressiveness, a sense of universality, with a touch of transcendence. Be sure to drink plenty of water.

Under the hood, x2c is a strict superset of C that compiles to C. You keep C’s native performance, tooling, ecosystem, and portability, and gain the conveniences of a modern language. A few new keywords extend C’s syntax, but the real magic is in meta: functions that run while the compiler builds your program as well as in the finished one, computing values and writing code.

Everything is optional and works with plain C, so you can adopt x2c one feature at a time in code you already have. The compiler, library, and runtime are themselves written in x2c, with no third-party library dependencies. Read the source to learn the language; edit it to change the language. The repository counts show how much there is to read.

Why learn a new language, let alone release one, in a post-AI world? Fair question. Programming is not about making computers do things; it’s about helping brains think things. The best reason to code is still to rewire your brain. So if programming is more than a career to you—if you code for love, power, or magic—try a bit of x2c.

Code is Love

Part of the pleasure of programming is finding a clear way to express an idea. C earns that love by putting you close to the machine, with little between you and what it can do. But that closeness comes at a cost: even simple ideas can take a lot of housekeeping to express.

x2c keeps that directness and lets you focus on what your program does. Describe a whole configuration as readable, nested data. Work with text and collections through operations you can combine. Read a file without managing line buffers. Give your own types methods that feel as natural as the built-ins. C’s functions, libraries, and control remain within reach.

Nobody ever fell in love with boilerplate. x2c leaves more room for what you do love: turning an idea into code.

More in the docs: values, symbols, collections and literals, files, and methods.

Code is Power

Count the words in a stream and rank them. Build and query a search index. Process a day’s files and release each one’s memory as you go, without a single free. Rewrite code by matching its shape. Send work to another thread and bring the answer back.

None of this needs a framework. In x2c, each capability gets more useful through the others: collections give your types something to build on, iterators connect operations into flows, and imports bring C libraries into the same style of code. Substantial computations become compact enough that you can still see the idea running through them.

The pieces are small. What you build with them needn’t be.

More in the docs: collections, iteration, scopes, match, threads, exceptions, and packages.

Code is Magic

When you can change the language, repetition starts to look like an opportunity. A pattern you keep writing can become a construct you use. An idea that once needed a page of explanation can have a name, a syntax, and rules the compiler understands.

Give sets their own operators. Turn a locking convention into a statement that always releases the lock. Describe a family of values once and let Lisp generate the code that follows from it. Inside the finished program, use that same Lisp to make rules into data you can pass around and evaluate.

The compiler is written in x2c, too. Follow an idea far enough and you can change the tool you are thinking with, in the language you already use.

More in the docs: protocols, macros and compile-time Lisp, runtime Lisp, self-hosting, compiler inspection, and architecture.

Install x2c

Install a release. One command downloads the compiler, runtime, headers, and examples for your platform into ~/.local/x2c. Then add packages from the package index with x2c install <package>. The release notes list what changed and how to upgrade.

Or build from source. Clone the repository, build the compiler from its checked-in C, and run one of the included examples. The compiler handles translation, native compilation, and execution.

You need a GCC- or Clang-compatible C compiler, ar, GNU Make, Python 3, and Bash. See the build instructions for the self-hosting process.

from install to a running program
git clone https://github.com/gwf/x2c.git
cd x2c
git checkout --detach aa2b9b2575297711e5978acc53f87bd7f645f3c7
make build-safe

curl -fsSL https://x2c-lang.dev/install.sh | sh
export PATH="$HOME/.local/x2c/bin:$PATH"
x2c run ~/.local/x2c/examples/foreach.x

# Or from a source checkout
./x2c run examples/foreach.x

# Strings, slicing, and interpolation
./x2c run examples/love/strings.x

# Generate C arrays with compile-time Lisp
./x2c run examples/magic/compile-time.x

Put libraries to work

Draw a chart, build a terminal app, query data, or train a model. Below is one working example from each package, with code, its result, and the complete source and setup instructions.

Packages give libraries their own namespaces, so you can use them together without name collisions. Build once, then import by name. Shims and adapters add idiomatic x2c types and methods while keeping the native API available; Lisp bindings and decorators can extend the language itself.

Browse packages or learn how to import one.

Build and run the chart example
# From your x2c checkout
make build-safe
./configure --packages raylib

make -C packages/raylib short-example
cd packages/raylib
./builds/climate-trends
# Result: builds/climate-trends.png

Packages need their native libraries prepared first. Release bundles are built on macOS and Linux, on both arm64 and x86_64.

about, docs, and source

Go further.

About x2c tells its story. Read the docs to learn the language and look up its library. Browse the source to see how it works or make it your own.

Repository counts from make stats.

compiler42,588 / 8,745

code / comment lines in the compiler source.

library21,877 / 9,667

code / comment lines in the library source.

X Lisp1,039 / 160

code / comment lines in hand-written X Lisp source.

compiler support748 / 115

code / comment lines in compiler support modules.

tests956

unit tests.

fixtures1,245

compiler fixtures.

examples56

showcase examples.

packagesBuild something.

Explore C libraries through working x2c examples.