Functions

A function has to be declared at the top level before it is called.

def foo(field a, field b) -> field:
    return a + b

def main() -> field:
    return foo(1, 2)

A function's signature has to be explicitly provided.

A function can be generic over any number of values of type u32.

def foo<N>() -> field[N]:
    return [42; N]

def main() -> field[2]:
    field[2] res = foo()
    return res

Functions can return multiple values by providing them as a comma-separated list.

def main() -> (field, field[3]):
    return 1, [2, 3, 4]

Inference

When defining a variable as the return value of a function, types are provided when the variable needs to be declared:

def foo() -> (field, field):
    return 21, 42

def main() -> field:
    // a is declared here
    field a = 1
    // b is declared here
    a, field b = foo()
    return 1