Hello World
Write, run, and build a minimal Zynx program.
Create main.zx:
import std.io;
fn main() {
io.println("Hello, Zynx");
}
Run the program:
./zynx run main.zx
# Hello, Zynx
Build an executable:
./zynx build main.zx
Or choose an explicit output path:
./zynx -o app main.zx
./app
# Hello, Zynx
When running directly from a source checkout, pass the development standard library path if imports are not found:
./zynx run --module-path=build/lib/zynx main.zx
import std.io makes the standard I/O module available as io.
io.println(text) writes borrowed text to standard output and appends a
newline. It is meant for simple human-facing CLI output and intentionally
ignores low-level write status. Use io.stdout.write or io.write when a
program must handle I/O errors.
Bare fn main() is the program entry point. It can use try without listing
every propagated error; the runtime prints propagated errors and exits nonzero.
Blocks use braces, and statements end with semicolons.
The compiler accepts fn main() -> void { ... }, but warns because the
explicit -> void is redundant.
This program computes a sum with an inclusive range and prints the result.
import std.io;
fn main() {
let total = 0;
for value in 1...4 {
total += value;
}
io.println("sum: {total}");
}
1...4 includes both endpoints. Use ..< for an exclusive end:
for index in 0..<3 {
io.println("{index}");
}
Test blocks are named with a string and run through the test command.
fn add(left: i32, right: i32) -> i32 {
return left + right;
}
test "integer math" {
assert add(20, 22) == 42, "addition should work";
}
./zynx test main.zx
Assertions in ordinary code use a boolean condition. Assertion messages are
currently accepted inside test blocks.
Read Type System, then Control Flow, then Strings and Interpolation.