Chapter I — Hello World

In this chapter, we'll explore write and run your first mana program.

Let's write the classic "Hello, World!" program in Mana.

Your First Program

Create a file called hello.mana:

module main
 
fn main() {
    println("Hello, Mana!")
}

Compile and Run

Mana compiles to C++, then to a native executable:

# Compile Mana to C++
mana hello.mana -o hello.cpp
 
# Build the C++ output
g++ -std=c++17 -I ~/.mana/include hello.cpp -o hello
 
# Run it
./hello

On Windows with Visual Studio, use the Developer Command Prompt:

mana hello.mana -o hello.cpp
cl /std:c++17 /I %USERPROFILE%\.mana\include hello.cpp /Fe:hello.exe
hello.exe

You should see:

Hello, Mana!

Understanding the Code

Module Declaration

Every Mana file starts with a module declaration:

module main

The main module is special—it's where your program's entry point lives. Note that semicolons are optional in Mana.

The main Function

fn main() {
    println("Hello, Mana!")
}
  • fn declares a function
  • main is the entry point for executables
  • The return type is optional for main (defaults to void/success)

The println Function

println is a built-in variadic function that prints values followed by a newline:

println("Hello, Mana!")

Variadic Print

Mana's println function accepts multiple arguments of any type:

let name = "World"
println("Hello, ", name, "!")

Any expression can be included as an argument:

let x = 10
let y = 20
println("The sum of ", x, " and ", y, " is ", x + y)

A Longer Example

module main
 
fn main() {
    // Immutable by default
    let x = 42
    let name = "Alice"
 
    // Mutable variables use 'mut'
    let mut counter = 0
    counter = counter + 1
 
    // Type annotations (optional with inference)
    // Note: 'int' and 'float' are aliases for i32 and f32
    let pi: float = 3.14159
    let flag: bool = true
 
    println("x = ", x, ", counter = ", counter)
    println("Hello, ", name, "!")
    println("Pi is approximately ", pi)
}

Next Steps

Now that you've run your first program: