Return Values
A function may return zero or more values using the return
keyword.
The return values must be specified in the function signature after the ->
symbol.
When a return
statement is executed, the function immediately exits and the outputs are returned.
fn FunctionWithReturnValue() -> name {
return "Augustus"
}
fn Example() {
let name = FunctionWithReturnValue
}
Multiple return values
A function may return multiple values.
When returning multiple values, the return
keyword must be followed by
a comma-separated list of identifiers.
fn GiveMeAPerson() -> name, age {
return "Augustus", 25
}
fn Example() {
let name, age = GiveMeAPerson
}
If more values are returned than needed, only the first value or first few values will be used, the rest will be ignored.
fn GiveMeAPerson() -> name, age {
return "Augustus", 25
}
fn Example() {
let contents = [GiveMeAPerson, "Fred"] // contents is ["Augustus", "Fred"]
let name = GiveMeAPerson // name is "Augustus" (age is ignored)
}
info
Multiple return values allow you to return additional auxiliary values that can be ignored when not needed. Some examples of this from Easel's built-in function library include PickRandom or QueryNearestAlongRay.