Skip to content
Systems programming for what’s next.
— Vex

Learn Vex through examples ​

Choose a task, then follow the linked program and the API contracts around it. The examples cover data modeling, resource ownership, concurrent work, compile-time programming, numerical code and application libraries.

Complete programs identify their filename, run command and expected behavior. Library fragments show a component to embed in a larger application; keep the surrounding imports, owners and error handling when adapting them.

Start with a small application ​

TaskWhat you practiceExample
Build a two-file library and its testsExported interfaces, imports, immutable/mutable values and test discoveryYour first project
Calculate a credit with rejected inputsA domain contract, typed failures and positive/negative testsTesting and benchmarking
Return either a value or a useful errorResult, match, early return and exit statusIntroduction, error handling
Build a command-line interfaceCommands, flags, arguments and help textCLI library
Read structured configurationOwning parsed values, lookup and conversion errorsJSON, TOML, YAML

Make ownership visible ​

TaskWhat you practiceExample
Validate a packet and return a borrowed payloadBounded views, error paths and keeping the owner aliveOwnership workflows
Build an independently owned reportBorrowed input, transformation and owned return valuesOwnership workflows
Call a small C functionA native header/provider, ABI selection and one cleanup ownerYour first native call
Work with file contents or mapped regionsI/O errors, resource cleanup, bytes and filesystem pathsFiles, filesystem API
Protect and authenticate a messageKey and nonce lifecycle, byte lengths and authentication failureEncryption

Coordinate independent work ​

TaskWhat you practiceExample
Collect a batch containing successes and failuresAsync jobs, tagged replies, Result and bounded channelsFallible task results
Merge producers and shut down cleanlyFan-in, completion counts, channel ownership and cancellationFan-in
Serve HTTP requestsRequest/response ownership, routes, middleware and body limitsFiber service, middleware
Store and query application stateConnection/statement lifetimes, parameter binding and transaction scopeDatabase connections, ORM

Move work into the compiler ​

TaskWhat you practiceExample
Calculate a bounded retry scheduleConst functions, strict compile-time values and overflow checksCompile-time recipes
Process fields selected by their exact typeTyped reflection and statically checked field accessCompile-time recipes
Generate repeated declarations from a typed descriptionDeclSet, generated methods/types and semantic checkingStructural generation
Share serialization metadata across modelsNamed policies, field tags, overrides and reflectionPolicies

Work with numbers, images and protocols ​

TaskWhat you practiceExample
Calibrate a batch of sensor valuesMultiple graph inputs, elementwise arithmetic, masks and reductionGraph functions
Differentiate a numerical expressionPrimal computation, forward-mode derivatives and sensitivitiesAutograd
Process a tile and its boundaryShape/index arithmetic and a scalar referenceFusion and tiled work
Measure a geographic journey or regionCoordinate order, units, distance and containmentGeographic coordinates
Transform an image in memoryPixel layout, owning images and deterministic transformsImage processing
Create PCM and describe it with a WAV headerSample layout, buffer sizes and container metadataMedia components
Inspect and reconstruct an RTP packetChecked parsing, network byte order and packet boundsReal-time protocols
Model a FIFOCapacity, occupancy, simultaneous operations and parameter widthsHardware examples

The hardware example belongs to the companion VexHDL project. GPU execution, native libraries and network peers each introduce their own environment; follow the linked page's setup and ownership contract.

Build a language tool ​

The language-tooling guide includes complete tokenizer and width-sensitive layout programs, a lossless syntax-tree fragment, and a map of the ten IDE library families. Extend those building blocks with grammar rules, source-labelled diagnostics, query metadata or editor messages.

When a compiler change needs a regression, use compiler testing tools to retain and replay generated cases. Application benchmarks and compiler-phase benchmarks measure different workloads; keep their inputs and results separate.

Adapt an example without losing its contract ​

Change one dimension at a time: input size, error case, ownership boundary, concurrency or target. Keep an expected result for each change. For a parser, include empty/truncated input; for a pipeline, include shutdown; for a numerical operation, compare to a reference with an explicit tolerance.

The capability map shows the broader language surface. The verification guide explains how to retain the command, compiler identity and result for your adaptation.

Released under the MIT License.