Skip to content

Hello World

Let’s write your first Zeus program! We’ll create a simple program that demonstrates the basics.

Your First Program

  1. Create a new file

    Create a file called hello.zs:

    Terminal window
    touch hello.zs
  2. Write the code

    Open hello.zs and add:

    function main(): void {
    log("Hello, World 👋");
    }
  3. Compile and run

    Terminal window
    zeus build hello.zs -o hello
    ./hello
    # Output: Hello, World 👋

Understanding the Code

Let’s break down what we wrote:

function main(): void {
log("Hello, World 👋");
}

The main Function

Every Zeus program needs a main function—this is where execution begins:

function main(): void {
// Your code here
}
  • function — Keyword to declare a function
  • main — The entry point function name
  • (): void — Takes no parameters, returns nothing

The log Function

log("Hello, World 👋");
  • log — Built-in function to print to stdout
  • Accepts a string (UTF-8 supported, including emojis! 🎉)

A More Interesting Example

Let’s try something with a class:

class Greeter {
public times: i32;
constructor(t: i32) {
this.times = t;
}
public greetCount(): i32 {
return this.times;
}
}
function main(): i32 {
let greeter: Greeter = new Greeter(5);
return greeter.greetCount();
}

Save this as greeter.zs and run:

Terminal window
zeus build greeter.zs -o greeter
./greeter
echo $?
# Output: 5

Working with Arrays

Here’s an example using dynamic arrays:

function main(): i32 {
// Create an array of integers
let numbers: i32[] = new i32[];
// Add some numbers
numbers.push(10);
numbers.push(20);
numbers.push(30);
// Access by index
let first: i32 = numbers.get(0);
let second: i32 = numbers.get(1);
return first + second; // Returns 30
}

Save as arrays.zs and run:

Terminal window
zeus build arrays.zs -o arrays
./arrays
echo $?
# Output: 30


What’s Next?