Oxeon’s basics are Rust’s. let bindings are immutable unless marked mut, and a binding can be shadowed by another with the same name. The last expression in a block is its value, so add needs no return.
Numeric literals take type suffixes (3.14159_f32, 1_000_000u64) and underscores, and can be written in hex or binary. Tuples are destructured with patterns, and [0u8; 16] creates an array of 16 zeros.
if is an expression, which parity uses. for loops run over ranges (0..10, 0..=10, and .rev()). A labelled loop can return a value with break 'label value, which found uses to leave two loops at once.
Integer arithmetic wraps on overflow, as in Rust’s release builds.
01_basics.ox
// Bindings, functions, control flow and primitive types.
fn add(a: i32, b: i32) -> i32 {
a + b // the last expression is the return value
}
fn basics() {
let x = 5;
let mut total: u64 = 0;
let x = x * 2; // shadowing
let pi = 3.14159_f32;
let big = 1_000_000u64;
let mask = 0xFF_u8;
let flags = 0b1010;
let letter = 'x';
let greeting = "hello";
let point = (3, 4);
let (px, py) = point;
let grid = [0u8; 16];
let first = grid[0];
if x > 5 && px != py {
total += 1;
} else if x == 0 {
total = 0;
} else {
total -= 1;
}
let parity = if x % 2 == 0 { "even" } else { "odd" };
for i in 0..10 {
total += i;
}
for i in (0..=10).rev() {
total += i;
}
let mut n = 3;
while n > 0 {
n -= 1;
}
let found = 'search: loop {
for i in 0.. {
if i * i > 50 {
break 'search i;
}
}
};
}