Skip to content

Function definitions

Functions can be defined through the use of the def keyword, as with other symbol types, such as interfaces, unions, and enums, they can be marked as public through the use of the prepended pub.

The syntax for function definitions is as follows:

def function_name(arg ArgType, arg2 ArgType2) ReturnType
    @puts("Doing stuff...")
end

Type arguments can also be passed to functions, these are called monomorphizable or "generic" functions, for example:

def add[T](x T, y T) T
    return x + y
end

To prevent strange type-errors from arising during compilation due to a programmer misunderstanding what a generic function allows, type arguments can be constrained like so:

def add[T: f32|f64|i32|i64](x T, y T) T
    # ...
end

In the above case, the type argument T is constrained to f32, f64, i32, and i64. Attempting to pass something other than that to T will result in a cleaner compile-time error.