# Returns

{% hint style="info" %}
Another big perk of functions is their ability to return a value (or even multiple values) back into the code it was called from. Not all situations require a return, but some do, and a return can be incredibly valuable.
{% endhint %}

A return's datatype is defined after a double colon on the function line:

{% code overflow="wrap" lineNumbers="true" %}

```python
#:          (    Parameters   )    (Return)
#:              V          V          V
function add(a:number, b:number) :: number:
  return ({_a} + {_b})
```

{% endcode %}

Similar to parameters, allow the function to return any object by setting the return type to `object`, and authorise the function to return multiple objects by pluralising the return datatype:

{% code overflow="wrap" lineNumbers="true" %}

```python
function exampleFunction() :: object:
#: This function can return a (single) object of any datatype

function exampleFunciton() :: locations:
#: This function can return a list (multiple) locations
```

{% endcode %}

To return an object, use the return effect: `return %object(s)%`.

{% hint style="warning" %}
Note that a function will terminate after returning something, so a return should be a function's last instruction.

A function with a return must not have any wait effects inside it.
{% endhint %}

{% hint style="info" %}
When a function has a return, it can be thought of like an expression; the function will be evaluated and 'replaced' with the return.

{% code overflow="wrap" lineNumbers="true" %}

```python
if add(10, 5) = 15: #: => if 15 = 15:
  broadcast "Math is cool!"
```

{% endcode %}

This means a function's return can also be used in effects or captured in a variable.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x8ight.gitbook.io/syntask/fundamentals/structures/functions/returns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
