Skip to content

Hello World

Let’s write your first Ferret program!

Create a file named main.fer in your project directory (folder).:

run
// Your first Ferret program
import "std/io";
fn main() {
let greeting: str = "Hello, World!";
io::Println(greeting);
}

Compile and run your program:

Terminal window
ferret main.fer

The compiler will produce a little program of the same name as your current project folder. So if your project folder is named hello, you’ll get an executable named hello (or hello.exe on Windows). Run it like this:

Terminal window
./hello # On Windows, use: ./hello.exe

Or compile with a custom output name:

Terminal window
ferret -o myapp hello.fer
./myapp

Let’s break down what’s happening:

  • fn main() - Every Ferret program starts with a main function
  • let greeting: str = "Hello, World!"; - Declares a variable with type annotation
  • io::Println(greeting); - Outputs the greeting to the console

Try modifying the program:

run
import "std/io";
fn greet(name: str) -> str {
return "Hello, " + name + "!";
}
fn main() {
let name: str = "Ferret";
let message: str = greet(name);
io::Println(message);
}