Core syntax Functions

# Functions

Top-level functions use the `def` keyword. They may declare typed parameters, default values, overloads, recursive behavior, explicit return types, and exception contracts.

Basic Declaration

    def add(a as Int, b as Int) as Int:
        return a + b

Default Arguments

    def greet(name as String = "World") as String:
        return "Hello, " + name

Overloading

    def add(a as Int, b as Int) as Int:
        return a + b

    def add(a as Double, b as Double) as Double:
        return a + b

Overloads are resolved by parameter types, so explicit typing is especially important here.

Returning Multiple Values

    def powers(n as Int):
        return n, n ** 2, n ** 3

    result = powers(10)
    a, b, c = powers(10)

Returning multiple comma-separated values produces a positional `Tuple<...Ts>` that can be stored or unpacked.

Recursion

    def fact(n as ULong) as ULong:
        return 1 if n == 0 else n * fact(n - 1)

Functions and Exceptions

Functions may raise exceptions as part of their normal implementation. Public APIs on types also commonly declare explicit `throws` clauses. The detailed exception model is covered in Exceptions and Resource Safety.

Functions Are Not Methods
Keep the two declaration styles separate

Top-level functions use `def`. Methods declared inside a class body do not. Inside a class you write declarations such as `public compute() as Int:` directly.