Skip to content

Hello World

Time to write your first Zeus program. Zeus source files use the .zs extension.

Your first program

  1. Create a file

    Terminal window
    touch hello.zs
  2. Write the code

    console.log("Hello, World πŸ‘‹")

    That’s it β€” no boilerplate.

  3. 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’s console.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
}
Terminal window
zeus run exit-code.zs
echo $? # 42

Module-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();
Terminal window
zeus run greeter.zs
# Hello!
# Hello!
# Hello!