Getting Started
Zap is a compiled systems programming language with an LLVM backend, ARC memory management, modern syntax, and explicit unsafe escape hatches. It targets developers who want predictable performance without GC pauses — and error handling that doesn’t look like noise.
Status: Early Alpha. The language is usable but not all features are finalized.
Installation
Section titled “Installation”Option 1 — Build from source
Section titled “Option 1 — Build from source”You need clang 21+, llvm 21+, cmake 20+, and doxygen installed.
git clone https://github.com/thezaplang/zap.gitcd zapchmod +x build.sh./build.shThe compiler will be at build/zapc. Add it to your PATH:
# bash / zshexport PATH="$PATH:/absolute/path/to/zap/build"Verify the installation:
zapc --versionzapc --helpOption 2 — Install script
Section titled “Option 2 — Install script”curl -fsSL https://zaplang.xyz/install-latest.sh | bashThis downloads the latest pre-built binary and adds zapc to your PATH automatically.
Your first program
Section titled “Your first program”Create a file called hello.zp:
import "std/io" { println };
fun main() Int { println("Hello, Zap!"); return 0;}Compile and run it:
zapc hello.zp -o hello./helloOutput:
Hello, Zap!What’s happening here
Section titled “What’s happening here”import "std/io" { println }— imports theprintlnfunction from the standard library’s I/O module.fun main() Int— the entry point.mainmust returnInt.println("Hello, Zap!")— prints a string followed by a newline.return 0;— returns exit code 0 (success). Every statement ends with;.
Compiler flags
Section titled “Compiler flags”| Flag | Description |
|---|---|
-o <name> | Set the output binary name |
--allow-unsafe | Enable unsafe blocks and raw pointer operations |
--help | Show all available flags |
# Compile with a custom output namezapc hello.zp -o hello
# Compile a program that uses unsafe featureszapc low_level.zp --allow-unsafe -o low_levelA slightly bigger example
Section titled “A slightly bigger example”Here’s a program that reads a name from stdin and greets the user:
import "std/io" { println, getLn };
fun greet(name: String) { println("Hello, " ~ name ~ "!");}
fun main() Int { println("What's your name?"); var name: String = getLn(); greet(name); return 0;}Key things to notice:
~is the string concatenation operator.var name: Stringdeclares a variable with an explicit type.- Functions without a return type are
Void— noreturnneeded. getLn()reads a line from stdin (fromstd/io).
What’s in the docs
Section titled “What’s in the docs”| Section | What you’ll learn |
|---|---|
| Variables | Primitive types, var, const, global, alias |
| Functions | Declarations, ref params, overloads, varargs, generics |
| Control Flow | if, while, break, ternary ?: |
| Arrays | Fixed-size arrays, indexing, nested arrays |
| Structs & Records | Named data types, field access, generics |
| Enums & Aliases | Closed value sets, @error enums, alias |
| Classes | Heap-allocated types, init, deinit, inheritance |
| ARC & Weak Refs | Memory model, reference cycles, weak |
| Generics | Generic functions, types, constraints, iftype |
| Error Handling | Failable functions, fail, ?, or, or err |
| Modules & Imports | import, pub, folder modules, stdlib list |
| Unsafe | Raw pointers, ext fun, FFI, std/mem |
Recommended learning path
Section titled “Recommended learning path”If you’re new to Zap, follow this order:
- Variables — types and declarations
- Functions — the building blocks
- Control Flow — conditionals and loops
- Structs & Enums — data modeling
- Classes — object-oriented features
- Error Handling — Zap’s approach to failures
- Modules — organizing code
- Generics — reusable, type-safe code
- Unsafe — when you need to go low-level
Doxygen reference
Section titled “Doxygen reference”The full API reference is available at docs.zaplang.xyz.