Skip to content

Syntax Basics

// Single-line comment
/*
Multi-line
comment
*/
let name = "Zap"
let pi = 3.14159
let active = true

Immutable bindings cannot be reassigned after declaration:

let x = 10
x = 20 // ✗ Compile error: cannot reassign immutable binding

Use mut when you need to reassign:

let mut counter = 0
counter = counter + 1 // ✓ OK

Type annotations are optional when the compiler can infer the type:

let x: Int = 42 // explicit
let y = 42 // inferred as Int
let name: String = "Zap" // explicit
Operator Description Example
+ Addition 3 + 4
- Subtraction 10 - 2
* Multiplication 6 * 7
/ Division 15 / 3
% Remainder 10 % 3
Operator Description Example
== Equal x == y
!= Not equal x != y
< Less than x < y
> Greater than x > y
<= Less or equal x <= y
>= Greater or equal x >= y
Operator Description Example
and Logical AND a and b
or Logical OR a or b
not Logical NOT not a

In Zap, almost everything is an expression — it produces a value:

// `if` is an expression
let status = if active { "on" } else { "off" }
// Block expressions — the last expression is the value
let result = {
let a = 10
let b = 20
a + b // evaluates to 30
}
let name = "world"
print("Hello, {name}!") // Hello, world!

Learn about Zap’s type system.