Skip to content

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.

You need clang 21+, llvm 21+, cmake 20+, and doxygen installed.

Terminal window
git clone https://github.com/thezaplang/zap.git
cd zap
chmod +x build.sh
./build.sh

The compiler will be at build/zapc. Add it to your PATH:

Terminal window
# bash / zsh
export PATH="$PATH:/absolute/path/to/zap/build"

Verify the installation:

Terminal window
zapc --version
zapc --help
Terminal window
curl -fsSL https://zaplang.xyz/install-latest.sh | bash

This downloads the latest pre-built binary and adds zapc to your PATH automatically.


Create a file called hello.zp:

import "std/io" { println };
fun main() Int {
println("Hello, Zap!");
return 0;
}

Compile and run it:

Terminal window
zapc hello.zp -o hello
./hello

Output:

Hello, Zap!
  • import "std/io" { println } — imports the println function from the standard library’s I/O module.
  • fun main() Int — the entry point. main must return Int.
  • println("Hello, Zap!") — prints a string followed by a newline.
  • return 0; — returns exit code 0 (success). Every statement ends with ;.

FlagDescription
-o <name>Set the output binary name
--allow-unsafeEnable unsafe blocks and raw pointer operations
--helpShow all available flags
Terminal window
# Compile with a custom output name
zapc hello.zp -o hello
# Compile a program that uses unsafe features
zapc low_level.zp --allow-unsafe -o low_level

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: String declares a variable with an explicit type.
  • Functions without a return type are Void — no return needed.
  • getLn() reads a line from stdin (from std/io).

SectionWhat you’ll learn
VariablesPrimitive types, var, const, global, alias
FunctionsDeclarations, ref params, overloads, varargs, generics
Control Flowif, while, break, ternary ?:
ArraysFixed-size arrays, indexing, nested arrays
Structs & RecordsNamed data types, field access, generics
Enums & AliasesClosed value sets, @error enums, alias
ClassesHeap-allocated types, init, deinit, inheritance
ARC & Weak RefsMemory model, reference cycles, weak
GenericsGeneric functions, types, constraints, iftype
Error HandlingFailable functions, fail, ?, or, or err
Modules & Importsimport, pub, folder modules, stdlib list
UnsafeRaw pointers, ext fun, FFI, std/mem

If you’re new to Zap, follow this order:

  1. Variables — types and declarations
  2. Functions — the building blocks
  3. Control Flow — conditionals and loops
  4. Structs & Enums — data modeling
  5. Classes — object-oriented features
  6. Error Handling — Zap’s approach to failures
  7. Modules — organizing code
  8. Generics — reusable, type-safe code
  9. Unsafe — when you need to go low-level

The full API reference is available at docs.zaplang.xyz.