A step-by-step tutorial
Fourteen chapters, hands-on. Every chapter has a runnable program and one focused new idea. Read it in order on the first pass; come back as a reference later. No prior capability-language experience is assumed: if you have written Python, Go, Rust, or any C-family language, you will feel at home.
Three things you need
- Capa installed and on your PATH. Check with capa --version; if not, see Get started.
- A text editor. Any editor works; for syntax highlighting and the language server, see editor integration on the install page.
- A terminal. Every chapter has a capa --run file.capa step.
From zero to real programs
Each chapter is short: 5-10 minutes of reading plus typing. You can stop after any chapter and have a working program.
01Hello, Capa
Your first program. The shape of main.
02Values and types
Primitives, let vs var, type inference, string interpolation.
03Functions
Signatures, parameters, return types, named arguments.
04Control flow
if, while, for, ranges, statement vs expression.
05Collections
List, Map, Set, higher-order methods.
06Structs and sum types
Defining your own types, pattern matching on variants.
07Errors as values
Option<T>, Result<T, E>, the ? operator.
08Your first capability
What Stdio really is. Why main declares it. The discipline.
09Attenuating capabilities
restrict_to. Monotonic narrowing. Least-authority programs.
10Defining your own capability
capability X, impl X for Y. Library contracts.
11Modules and visibility
import, pub, CAPA_PATH.
12A small project
Putting it together. A real CLI tool in Capa.
13Information-flow control
@secret, declassify, and proving data cannot leak.
14From source to SBOM
--manifest, --cyclonedx, --spdx, --vex, --provenance.