Hello World
Let’s write your first Zeus program! We’ll create a simple program that demonstrates the basics.
Your First Program
-
Create a new file
Create a file called
hello.zs:Terminal window touch hello.zs -
Write the code
Open
hello.zsand add:function main(): void {log("Hello, World 👋");} -
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 functionmain— 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:
zeus build greeter.zs -o greeter./greeterecho $?# Output: 5Working 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:
zeus build arrays.zs -o arrays./arraysecho $?# Output: 30