Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax Mapping

Complete mapping between classic and natural forms. Both compile to identical AST nodes.

Variables

ClassicNaturalDescription
let x = 5set x to 5Immutable binding
let mut x = 0set mut x to 0Mutable binding
x = 10change x to 10Reassignment
let {a, b} = objunpack {a, b} from objDestructuring
// Classic
let name = "Alice"
let mut count = 0
count = count + 1

// Natural
set name to "Alice"
set mut count to 0
change count to count + 1

Functions

ClassicNaturalDescription
fn add(a, b) { }define add(a, b) { }Function definition
async fn fetch() { }forge fetch() { }Async function
return valuereturn valueReturn (same in both)
// Classic
fn greet(name) {
    return "Hello, " + name
}

// Natural
define greet(name) {
    return "Hello, " + name
}

Control Flow

ClassicNaturalDescription
else { }otherwise { }Else branch
else { }nah { }Else branch (casual)
else ifotherwise ifElse-if branch
// Classic
if x > 0 {
    say "positive"
} else if x == 0 {
    say "zero"
} else {
    say "negative"
}

// Natural
if x > 0 {
    say "positive"
} otherwise if x == 0 {
    say "zero"
} nah {
    say "negative"
}

Output

ClassicNaturalDescription
println("text")say "text"Print with newline
print("text")print("text")Print without newline
yell "text"Print uppercased
whisper "text"Print lowercased

Types and Structures

ClassicNaturalDescription
struct User { }thing User { }Struct definition
impl User { }give User { }Method implementation
interface Printable { }power Printable { }Interface definition
enum Color { }craft Color { }Enum definition
// Classic
struct User {
    name: string,
    age: int
}

impl User {
    fn greet(self) {
        say "Hi, I'm " + self.name
    }
}

// Natural
thing User {
    name: string,
    age: int
}

give User {
    fn greet(self) {
        say "Hi, I'm " + self.name
    }
}

Async / Concurrency

ClassicNaturalDescription
async fn x() { }forge x() { }Async function
await exprhold exprAwait an async value
yield valueemit valueYield from a generator
fetch("url")grab resp from "url"HTTP fetch
// Classic
async fn get_data() {
    let resp = await fetch("https://api.example.com/data")
    return resp
}

// Natural
forge get_data() {
    let resp = hold grab data from "https://api.example.com/data"
    return resp
}

Pattern Matching

ClassicNatural
match value { }match value { }
when value { }when value { }

Both match and when are available; when supports guard-style syntax unique to Forge (see Innovation Keywords).

Modules

ClassicNaturalDescription
has InterfaceNamehas InterfaceNameInterface conformance assertion

The has keyword asserts that a type satisfies an interface at the point of declaration.