Knowing yourself is the beginning of all wisdom.
— Aristotle
Variables and Types
Wyzer is statically typed, but the compiler can often infer the type based on the value you assign.
Declaring Variables
You declare variables based on whether their values can change:
fn variables() {
let x = 5;
// x = 6; // Error: cannot mutate a `let` binding
var y = 10;
y = 20; // Allowed
const MAX_USERS: u32 = 100;
}
Breaking it down
let(Immutable): By default, variables are immutable. You cannot changexafter assigning it.var(Mutable): If you need to reassign a variable later, usevar.const(Compile-Time Constant): For values that never change, useconst. You must explicitly declare the type (e.g.,u32).
Primitive Types
Wyzer provides a standard set of numeric and text types:
let count: u32 = 42;
let pi: f32 = 3.14;
let is_active: bool = true;
let letter: char = 'W';
let greeting: str = "Welcome to Wyzer";
Breaking it down
- Integers: Signed (
i8toi128) and unsigned (u8tou128).usizedepends on your system architecture. - Floating-Point:
f8,f16,f32,f64,f128. bool:trueorfalse.- Text:
charfor single characters (single quotes) andstrfor strings (double quotes).
Compound Types
You can group multiple values together:
let coord: (u32, u32) = (10, 20);
let numbers: [u32] = [1, 2, 3];
Breaking it down
- Tuples (
(10, 20)): A fixed-length grouping of potentially different types. - Arrays (
[1, 2, 3]): A fixed-length collection where every element must have the same type.