# Inline

#### Example

Here's a basic example of an inline function that adds two numbers:

```javascript
add = def(x, y) -> (
  return x + y
)

// Usage
result = add(5.0, 3.0)
```

In this example, `add` is an inline function that takes two arguments, `x` and `y`, and returns their sum. This function can be called multiple times throughout your shader code to perform addition operations.

## Functions as arguments

In osl you can use a function as arguments for other functions, methods and commands. This allows for powerful new syntax such as the `.map()` method which iterates over each item in an array and overwrites it based on the function it is passed as argument.

```javascript
arr = [1,2,3,4,5]

log arr.map(def(item) -> (
  return item * 2
  // set each item to itself * 2
))

// [2,4,6,8,10]
```

You can also define a function earlier and then pass it as input

```javascript
arr = [1,2,3,4,5]

// define the function into the global func variable
func = def(item) -> (
  return item * 2
  // set each item to itself * 2
)

log arr.map(func)
// pass the function as a parameter

// [2,4,6,8,10]
```


---

# 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://osl.mistium.com/custom-syntax/inline.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.
