Keywords
Language keywords for declarations, control flow, and more.
Overview
| Keyword | Description |
|---|---|
fn |
Declares a function with a stack signature |
pub |
Makes a function, constant, or struct visible to other modules |
const |
Declares a compile-time constant value |
struct |
Declares a structured data type with named fields |
use |
Imports a module |
if |
Conditional execution |
else |
Alternative block when if condition is false |
for |
Iteration with counter |
while |
Conditional loop |
loop |
Infinite loop |
break |
Exit loop |
continue |
Skip to next iteration |
return |
Exit function |
defer |
Schedule cleanup code |
switch |
Multi-way branching |
_ |
Wildcard/default case in switch |
ctx |
Context variable access |
-> |
Variable binding |
true |
Boolean true (1) |
false |
Boolean false (0) |
Declarations
fn
Declares a function with a stack signature.
fn add(a:i64 b:i64 -- sum:i64) {
+
}
pub
Makes a function, constant, or struct visible to other modules.
pub fn greet() {
"Hello" print nl
}
const
Declares a compile-time constant value.
const Pi = 3.14159
struct
Declares a structured data type with named fields.
struct Point {
x:f64
y:f64
}
use
Imports a module, making its functions available with module::function syntax.
use str
Control flow
if
Executes a block if the top of stack is true (non-zero).
5 3 > if {
"yes" print
}
else
Provides an alternative block when the if condition is false.
x 0 > if {
"positive"
} else {
"non-positive"
}
for
Iterates from start to end with a step, binding the iterator variable.
0 10 1 for i {
i print nl
}
while
Repeats a block while the condition is true. The condition is evaluated before entering and at the end of each iteration.
0 -> i
i 5 < while {
i print nl
i 1 + -> i
i 5 < // condition for next iteration
}
loop
Repeats a block indefinitely until break is called.
loop {
"forever"
print nl
}
break
Exits the innermost loop immediately.
loop {
x 10 > if {
break
}
}
continue
Skips to the next iteration of the innermost loop.
0 10 1 for i {
i 5 == if {
continue
}
i print nl
}
return
Exits the current function immediately.
fn early() {
true if {
return
}
"not reached" print
}
switch
Branches based on matching the top of stack against case values.
x switch {
1 {
"one"
}
2 {
"two"
}
_ {
"other"
}
}
_ {#wildcard}
Provides a fallback block when no switch case matches.
_ {
"no match" print
}
Other keywords
defer
Schedules a block to run when the function exits, in LIFO order.
defer {
file io::close
}
ctx
Creates a new isolated stack context with a copy of the parent stack, not allowing access to parent stack values.
ctx {
// child context
}
->
Pops a value from the stack and binds it to a local variable.
42 -> x
true
Pushes 1 onto the stack.
true if {
"yes" print
}
false
Pushes 0 onto the stack.
false if {
} else {
"no" print
}