Function Calls
This page describes argument passing rules for function and method calls in Zynx.
Positional and Keyword Arguments
Zynx supports positional arguments and keyword (named) arguments.
Rules:
- You may use only positional arguments.
- You may mix positional and keyword arguments.
- If mixed, positional arguments must come first.
- Keyword arguments must follow parameter order (no reordering).
Examples:
fn sum(a: i32, b: i32, c: i32 = 0) -> i32 {
return a + b + c;
}
let x = sum(1, 2); // positional only
let y = sum(1, b: 2, c: 3); // positional -> keyword
let z = sum(a: 1, b: 2); // keyword only, ordered
Invalid:
sum(a: 1, 2); // positional after keyword
sum(c: 3, a: 1); // keyword reordering
Default Parameters
Parameters may provide default values.
fn pick(a: i32 = 1, b: i32 = 2) -> i32 {
return a + b;
}
let p1 = pick(); // 3
let p2 = pick(a: 3); // 5
let p3 = pick(a: 3, b: 4); // 7
When a parameter is omitted, its default value is used.