Functions

Define reusable functions.

fn

Parameters and return types are optional when inferred; here they are explicit for learning.

fn double(n){
    return n + n
}

fn main() {
    print(double(5))
}

Output

10

Shorthand body

Single-expression function with =.

fn square(n)= n * n

fn main() {
    print(square(4))
}

Output

16