Hello World
Time to write your first Zeus program. Zeus source files use the .zs extension.
Your first program
-
Create a file
Terminal window touch hello.zs -
Write the code
console.log("Hello, World π")Thatβs it β no boilerplate.
-
Run it
Terminal window zeus run hello.zs# Output: Hello, World πTo keep the compiled binary instead of running it directly, use
zeus build:Terminal window zeus build hello.zs -o hello./hello
Understanding the code
console.log("Hello, World π")consoleβ a global object available in every program, no import needed..logβ prints to stdout with a trailing newline, like JavaScriptβsconsole.log.- Strings are full UTF-8, so emojis π work out of the box.
Zeus also provides console.error (stderr) and console.info (stdout):
console.log("info message")console.error("something went wrong")console.info("another info message")Controlling the exit code
A program exits with code 0 by default. To return a specific exit code β for scripts, CI, or
error signaling β define an optional main function that returns i32:
function main(): i32 { console.log("starting up") return 42 // becomes the process exit code}zeus run exit-code.zsecho $? # 42Module-level code runs directly, so main() is never required:
console.log("module-level code runs")A slightly bigger example
class Greeter { public times: i32;
constructor(t: i32) { this.times = t; }
public greet(): void { let i = 0; while (i < this.times) { console.log("Hello!") i = i + 1; } }}
let greeter = new Greeter(3);greeter.greet();zeus run greeter.zs# Hello!# Hello!# Hello!