# Introduction

Vex is a systems programming language built around explicit memory ownership,
concurrent execution, and data-parallel computation. This guide introduces the
0.4.0 programming model through complete programs and links to the more detailed
language and library references.

## The basic idea

Vex keeps ordinary systems code readable while making the important costs visible:

- bindings are immutable unless mutation is written explicitly with let!;
- values are moved or borrowed according to ownership rules;
- go blocks, channels, async, and await are part of the language surface;
- arrays and tensor-shaped operations can be lowered through Silicon IR (SIR);
- FFI, typed pointers, spans, and raw buffers provide controlled low-level escape hatches.

These parts are not equally mature. Core syntax, data types, ownership, and the checker have the strongest coverage. Concurrency, SIR, GPU backends, FFI, and platform-specific tooling are documented as experimental where their behavior is still being developed. See the [Language Status](language-status.md) page before choosing a feature for production work.

## A complete first program

Create hello.vx:

~~~vex [hello.vx]
fn main(): i32 {
    let language = "Vex";
    $println("Hello from ", language);
    return 0;
}
~~~

With the selected compiler on `PATH`, check and run it from the directory
containing `hello.vx`:

~~~text
vex lint hello.vx
vex run hello.vx
~~~

The program prints `Hello from Vex` and exits with status 0. The compiler
reports syntax and semantic errors before producing a program. The
[installation guide](installation.md) covers compiler packages, source
builds, and selecting the executable.

## A small data model

Structs hold related fields. Methods are declared outside the struct with a receiver:

~~~vex [point.vx]
struct Point {
    public:
    x: i32,
    y: i32,
}
fn (point: &Point) coordinate_sum(): i32 {
    return point.x + point.y;
}
fn main(): i32 {
    let positive = Point { x: 3, y: 4 };
    let negative = Point { x: -3, y: 1 };
    let origin = Point { x: 0, y: 0 };
    $println(positive.coordinate_sum());
    $println(negative.coordinate_sum());
    $println(origin.coordinate_sum());
    return 0;
}
~~~

This prints `7`, `-2`, and `0` on separate lines and exits 0. `coordinate_sum` adds signed coordinates; it is not a distance function.

`&Point` is an immutable borrow. A mutable receiver is written `&Point!`; mutation also requires the value at the call site to be held in a mutable binding. The complete rules are in [Ownership](memory/ownership.md) and [Borrowing](memory/borrowing.md).

## Explicit failure values

Vex uses `Result<T, E>` for recoverable failure. This example divides
nonnegative quantities into a positive number of groups and propagates an
invalid-input error with `?`:

~~~vex
fn divide(left: i32, right: i32): Result<i32, i32> {
    if left < 0 || right <= 0 {
        return Err(1);
    }
    return Ok(left / right);
}

fn calculate(): Result<i32, i32> {
    let first = divide(20, 4)?;
    return Ok(first + 1);
}

fn main(): i32 {
    return match calculate() {
        Ok(value) => { $println(value); 0 },
        Err(code) => code,
    };
}
~~~

This program prints `6` and exits 0. Replacing `divide(20, 4)` with
`divide(20, 0)` propagates `Err(1)` and exits 1 without printing a successful
value. Integer division truncates any remainder; this is a small integer
example, not a decimal calculator. `Option<T>` models an absent value.
See [Enums](types/enums.md), [Option](types/option-api.md),
[Result](types/result-api.md), and [Error Handling](error-handling.md).

## What makes Vex different

### Mutation is visible

`let` is immutable. Use `let!` when a local must change:

~~~vex
fn main(): i32 {
    let! total = 0;
    total += 2;
    total += 3;
    $println(total);
    return 0;
}
~~~

The program prints `5` and exits 0. The numeric result is program output;
`main`'s return value is the process status. Explicit mutation makes the places
that can change state visible in the source.

### Concurrency is explicit

A `go` block schedules work, while a channel provides a typed communication path:

~~~vex
fn main(): i32 {
    let! channel: Channel<i64> = Channel(1);

    go {
        channel.send(42);
    };

    let value = <-channel;
    $println(value);
    return 0;
}
~~~

The channel connects the producer's value to the receiver. Capacity, input
ownership and shutdown determine how a larger program coordinates its tasks.
Continue with [Concurrency Overview](concurrency/overview.md),
[Channels](concurrency/channels.md) and a
[batch of fallible jobs](concurrency/batch-results.md).

### Data parallelism has a compiler path

Vex includes operations intended to describe work over arrays and tensors. The SIR pipeline can lower eligible operations to target-specific code, but no source program should assume that every operation will be vectorized or that every GPU backend supports the same set of features. Read [SIMD](simd/index.md) and [GPU & SIR](gpu/index.md) together with the status notes on those pages.

## A practical learning path

1. [Install the compiler](installation.md).
2. Learn [syntax](basics/syntax.md), [variables](basics/variables.md), [functions](basics/functions.md), and [control flow](basics/control-flow.md).
3. Build data models with [primitive types](types/primitives.md), [structs](types/structs.md), [enums](types/enums.md), and [pattern matching](types/pattern-matching.md).
4. Learn the memory model through [ownership](memory/ownership.md), [borrowing](memory/borrowing.md), and [lifetimes](memory/lifetimes.md).
5. Add recoverable failure with [error handling](error-handling.md).
6. Explore [modules](modules.md), [testing](tooling/testing.md), and the [standard library](stdlib.md).
7. Combine those foundations with [async](concurrency/async.md),
   [SIR](simd/sir-pipeline.md), [GPU programming](gpu/index.md),
   [compile-time generation](advanced/comptime-recipes.md) or [FFI](ffi.md).
8. Use the [capability map](language-status.md) and
   [example collection](examples.md) to choose a practical next project.

## Source of truth

The language guide describes the intended user-facing model. The compiler tests and checked examples determine what the current toolchain accepts. Design notes under the repository's docs/ directory can describe future work and should not be treated as stable syntax unless the corresponding guide page says that the feature is implemented.

When reporting an example, include its page, exact command, source and compiler
version through the [contribution guide](contributing.md#reporting-a-problem).
