Version: 1.1.0

Function declarations

A function declaration is its name, parameters, argument conventions, effects, and return type.

Essentials

  • def allows default arguments and a more dynamic calling style.
  • fn requires explicit conventions and is the stricter form.
  • Parameters go in []. Arguments go in ().
  • raises is an effect. So is a future async marker.
  • Variadic arguments collect extra positional values.

Example

fn dot[n: Int](read a: SIMD[DType.float32, n], read b: SIMD[DType.float32, n]) -> Float32:
    return (a * b).reduce_add()

Keep in mind

Put the effects in the signature. Callers should not have to open the body to learn that a function can fail.