--- layout: tour title: A Tour of Jam - Basics permalink: /tour/ progress: 25 current_chapter: 1 total_chapters: 4 chapter_title: The Basics chapter_intro: Welcome to the tour. This guide will walk you through the fundamental building blocks of Jam. By the end, you'll be ready to write your first sweet application. chapters: - number: "01" name: Basics active: true - number: "02" name: Control Flow active: false - number: "03" name: Types active: false next_chapter: url: "#" title: Control Flow & Logic description: Learn about if, else, and pattern matching. ---
In Jam, we use const for immutable bindings and var for mutable ones.
Using const by default helps prevent bugs where data changes unexpectedly.
If you need to change a value, use var to make it mutable.
const std = import("std"); // Immutable binding const name: str = "Strawberry"; // name = "Grape"; // Error! Cannot reassign const // Mutable binding var count: u8 = 10; count = 11; // This is fine with var std.fmt.println("Making jam!");
Functions are declared with fn. They are strictly typed, ensuring you always know what goes in and what comes out.
Return types are specified directly after the parameter list. Use return to return values from a function.
fn addSugar(amount: i32) i32 { return amount + 10; } fn greet() { // No return type = void function std.fmt.println("Hello!"); } fn main() u8 { greet(); return 0; }
Jam uses import() to bring in modules. The standard library provides common utilities.
Use std.fmt for formatting and printing, std.thread for timing and threading.
const std = import("std"); fn main() u8 { std.fmt.println("Hello, World!"); std.fmt.print("Waiting..."); std.thread.sleep(1000); // 1 second std.fmt.println("Done!"); return 0; }