Skip to content

Parameters

You can use multiple types of parameters in Ferret functions.

fn add(a: i32, b: i32) -> i32 {
return a + b;
}

Parameters can be optional:

fn greet(name: str, title: str?) -> str {
if title != none {
return "Hello, " + title + " " + name;
}
return "Hello, " + name;
}

Accept multiple arguments:

fn sum(numbers: ...i32) -> i32 {
let total := 0;
for n in numbers {
total = total + n;
}
return total;
}
let result := sum(1, 2, 3, 4, 5); // 15