> For the complete documentation index, see [llms.txt](https://wu-lang.gitbook.io/guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wu-lang.gitbook.io/guide/syntax/functions.md).

# Functions

Wu functions are expressions, but can also be declared using the same notation as `struct`. For example we can declare functions like this:

```fsharp
add_two: fun(a: int) {
    a += 2
}
```

The following is just as valid, but more ugly:

```fsharp
add_two := fun(a: int) {
    a += 2
}
```

{% hint style="info" %}
They are the exact same behind the scenes. No difference at all.
{% endhint %}

Functions return the last expression in their body implicitly(like in Rust) like so:

```fsharp
ten: fun {
    10
}

print(ten()) # 10
```

{% hint style="info" %}
Why have parentheses if they're empty anyways?
{% endhint %}

You are still able to use explicit returns:

```fsharp
twenty: fun {
    return ten() + ten()
}
```

Of course, as we're dealing with a decent language, higher order functions are a thing:

```fsharp
apply: fun(f: fun(int) -> int, a: int) -> int {
    f(a)
}

# 12
apply(fun(a: int) { a + 2 }, 10)
```

Now for something vaguely interesting. Splats are basically a catchall parameter, that binds as many arguments you throw at it into an array:

```fsharp
choose_first: fun(things: ...) -> any {
    things[0]
}

a := choose_first(1, 2, 3, 4, 5, 6)

print(a) # 1
```

Of course we can type the splats:

```fsharp
choose_second: fun(floats: ...float) -> float {
    floats[1]
}

a := choose_second(1.0, 2.1, 3.8)

print(a) # 2.1
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://wu-lang.gitbook.io/guide/syntax/functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
