Nex

Examples

A feature tour followed by complete programs from hello-world to a recursive FFT.

Two parts to this section.

The Tour is every language feature shown in small, focused snippets — read it if you want to see what the language is. The Programs are complete real programs combining features — read them if you want to see what programs look like.

All code is valid against the language reference. Built-in functions (sqrt, sum, map, …) and constants (pi, e, i, …) come from the implicit prelude.

Pages

  • Tour — Every language feature in small, focused snippets — literals, bindings, blocks, arithmetic, arrays, structs, lambdas, functions, modes, closures, control flow, prelude, testing, modules.
  • Hello, world — The first program — print to stdout — followed by a function and a calculation.
  • Arrays and Structs — Element-wise array operations that fuse to one loop, and a small struct with a function over it.
  • Higher-Order Functions and Closures — A closure captures `mean`, then `.map` fuses into the `.sum` reduction.
  • Complex Numbers and the Quadratic Formula — Complex arithmetic, then a quadratic solver returning a pair of complex roots.
  • Multi-File Modules — Descriptive statistics across three files in one module folder, with inline tests that see private helpers.
  • Numerical Methods — Newton's method for square roots, then one Runge-Kutta 4 step for a vector ODE.
  • Three Ways to Express the Same Computation — The same `normalize` algorithm written three ways — functional (fuses to one loop), explicit-loop with a local `var`, and slice assignment for partial in-place updates.
  • Mandelbrot Set — Rank-2 matrix plus complex iteration — escape-time rendered as ASCII art. Row-vector slice assignment writes a whole row of the image with one statement.
  • Sum of Sinusoids — A three-term wave function and a partial Fourier sum, sampled over [0, 1].
  • Power Iteration — Dominant eigenvalue and eigenvector of a square matrix via the `@` operator and `dot`.
  • Dedicated @test Modules — A sibling test-only module with support code and table-driven fixtures, stripped from non-test builds.
  • FFT — Cooley-Tukey radix-2 recursive FFT for any power-of-2 N — complex numbers, strided slicing for the even/odd split, element-wise array arithmetic, and slice assignment to stitch the two output halves.
  • Sum Types and Match — Modeling a Newton-style solver's outcomes with an enum, then dispatching with match.
  • Writing a PPM image with `[byte]` — Build a small gradient image as a `[byte]` buffer in P6 (binary PPM) format and dump it to disk with `write_bytes`.

Search

Esc
to navigate to open Esc to close