Hello World
Let’s write your first Ferret program!
Create a File
Section titled “Create a File”Create a file named main.fer in your project directory (folder).:
// Your first Ferret programimport "std/io";
fn main() { let greeting: str = "Hello, World!"; io::Println(greeting);}Run the Program
Section titled “Run the Program”Compile and run your program:
ferret main.ferThe 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:
./hello # On Windows, use: ./hello.exeOr compile with a custom output name:
ferret -o myapp hello.fer./myappUnderstanding the Code
Section titled “Understanding the Code”Let’s break down what’s happening:
fn main()- Every Ferret program starts with amainfunctionlet greeting: str = "Hello, World!";- Declares a variable with type annotationio::Println(greeting);- Outputs the greeting to the console
Try It Yourself
Section titled “Try It Yourself”Try modifying the program:
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);}