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

Keywords

Keywords are reserved identifiers with special syntactic meaning. A keyword cannot be used as a variable name, function name, or type name.

Forge’s keyword set is organized into five categories: classic keywords (familiar from other languages), natural-language keywords (Forge’s English-like alternatives), innovation keywords (unique to Forge), error handling keywords, and type keywords.

Classic Keywords

These keywords provide syntax familiar to developers coming from Rust, JavaScript, Go, or Python.

KeywordPurpose
letVariable declaration
mutMutable variable modifier
fnFunction declaration
returnReturn from function
ifConditional branch
elseAlternative branch
matchPattern matching
forFor loop
inIterator binding (used with for)
whileWhile loop
loopInfinite loop
breakExit a loop
continueSkip to next loop iteration
structStruct type definition
typeAlgebraic data type definition
interfaceInterface definition
implMethod block / interface implementation
pubPublic visibility modifier
importModule import
spawnSpawn a concurrent task
trueBoolean literal true
falseBoolean literal false
nullNull literal
asyncAsync function declaration
awaitAwait an async expression
yieldYield a value from a generator

Natural-Language Keywords

These keywords provide English-like alternatives to classic syntax. Each natural keyword maps to an equivalent classic construct.

Natural KeywordClassic EquivalentUsage
setletset x to 5
to=Used with set and change
change(reassignment)change x to 10
definefndefine greet(name) { }
otherwiseelse} otherwise { }
nahelse} nah { } (informal)
each(loop modifier)for each x in items { }
repeat(counted loop)repeat 5 times { }
times(loop count)Used with repeat
grab(fetch)grab resp from "url"
from(source)Used with grab and unpack
wait(sleep)wait 2 seconds
seconds(time unit)Used with wait and timeout
sayprintlnsay "hello"
yell(uppercase print)yell "hello" prints HELLO
whisper(lowercase print)whisper "HELLO" prints hello
thingstructthing Person { }
powerinterfacepower Describable { }
giveimplgive Person { }
craft(constructor)craft Person { name: "A" }
the(connector)give X the power Y { }
forgeasyncforge fetch_data() { }
holdawaithold expr
emityieldemit value
unpack(destructure)unpack {a, b} from obj

Dual Syntax Mapping

The following table shows equivalent forms for the most common constructs:

ConstructClassicNatural
Variablelet x = 5set x to 5
Mutable variablelet mut x = 0set mut x to 0
Reassignmentx = 10change x to 10
Functionfn add(a, b) { }define add(a, b) { }
Else branchelse { }otherwise { } / nah { }
Struct definitionstruct Point { }thing Point { }
Interfaceinterface I { }power I { }
Impl blockimpl T { }give T { }
Impl for interfaceimpl I for T { }give T the power I { }
ConstructorPoint { x: 1 }craft Point { x: 1 }
Async functionasync fn f() { }forge f() { }
Awaitawait exprhold expr
Yieldyield valueemit value
Destructurelet {a, b} = objunpack {a, b} from obj

Innovation Keywords

These keywords introduce constructs unique to Forge that have no direct equivalent in other mainstream languages.

KeywordPurposeExample
whenGuard expression (multi-way conditional)when age { < 13 -> "kid" }
unlessPostfix negative conditionalexpr unless condition
untilPostfix loop-untilexpr until condition
mustCrash on error with messagemust parse_int(s)
checkDeclarative validationcheck name is not empty
safeNull-safe execution blocksafe { risky_code() }
whereCollection filteritems where x > 5
timeoutTime-limited executiontimeout 5 seconds { }
retryAutomatic retry with countretry 3 times { }
scheduleCron-style schedulingschedule every 5 minutes { }
everyUsed with scheduleschedule every N { }
anyExistential quantifierany x in items
askAI/LLM promptask "summarize this"
promptPrompt template definitionprompt summarize() { }
transformData transformation blocktransform data { }
tableTable displaytable [...]
selectQuery-style selectfrom X select Y
orderQuery-style orderingorder by field
byUsed with order and sortorder by name
limitQuery-style limitlimit 10
keepFilter synonymkeep where condition
takeTake N itemstake 5
freezeFreeze/immobilize a valuefreeze expr
watchFile change detectionwatch "file.txt" { }
downloadDownload a file from URLdownload "url" to "path"
crawlWeb scrapingcrawl "url"

Error Handling Keywords

KeywordPurposeExample
tryTry blocktry { }
catchCatch blockcatch err { }

Type Keywords

These identifiers are reserved as built-in type names. They are recognized by the lexer as keyword tokens, not as general identifiers.

KeywordType
Int64-bit signed integer
Float64-bit IEEE 754 float
StringUTF-8 string
BoolBoolean
JsonJSON value type

Operators as Keywords

The following operators are lexed as keyword tokens rather than punctuation:

TokenKeywordMeaning
|>PipePipe-forward operator
>>PipeRightAlternate pipe operator
...DotDotDotSpread operator
+=PlusEqAdd-assign
-=MinusEqSubtract-assign
*=StarEqMultiply-assign
/=SlashEqDivide-assign

Complete Alphabetical Index

For reference, the complete set of keyword strings recognized by the lexer (case-sensitive):

Int, Float, String, Bool, Json,
any, ask, async, await, break, by, catch, change, continue, craft,
crawl, define, download, each, else, emit, every, false, fn, for,
forge, freeze, from, give, grab, hold, if, impl, import, in,
interface, keep, let, limit, loop, match, mut, nah, null, order,
otherwise, power, prompt, pub, repeat, retry, return, safe, say,
schedule, seconds, select, set, spawn, struct, table, take, the,
thing, timeout, times, to, transform, true, try, type, unless,
unpack, until, wait, watch, when, where, while, whisper, yell, yield

All keywords are case-sensitive. Let and LET are identifiers, not keywords. The type keywords Int, Float, String, Bool, and Json are the only keywords that begin with an uppercase letter.