Function Declarations
Learn how to declare typed functions, manage arguments, and return values with explicit signatures.
Function Declaration Syntax
Functions are declared with the fun keyword, followed by typed parameters and a mandatory return arrow (->):
fun add(a: int, b: int) -> int {
return a + b;
}
let sum: int = add(15, 25);
print("Sum is:", sum); // 40
Parameter Type Checking
NouvaLang guarantees that the arguments passed at call sites strictly match the parameter type annotations:
fun calculate_area(width: float, height: float) -> float {
return width * height;
}
print(calculate_area(5.5, 4.0)); // 22.0
Early Returns
You can use the return statement at any point in the function body to exit early:
fun check_access(age: int) -> str {
if age < 18 {
return "Access Denied";
}
return "Access Granted";
}