Skip to main content

Function Declaration

Functions in Soul are declared with the soul keyword:

Parameters and Arguments

Functions can accept multiple parameters:
Soul doesn’t support default parameters or named arguments. All parameters must be provided when calling a function.

Return Values

Use the return keyword to return a value:

First-Class Functions

Functions are first-class values in Soul - they can be assigned to variables, passed as arguments, and returned from other functions:

Assigning Functions to Variables

Functions as Arguments

Returning Functions

Anonymous Functions

Create functions without names:

Closures

Functions can capture variables from their enclosing scope:

Function Scope

Each function creates its own scope:

Recursion

Functions can call themselves:

Higher-Order Functions

Soul supports functional programming patterns:

Best Practices

Functions should do one thing well. If a function is getting too large, consider breaking it into smaller functions.