---
title: "function — Function definition"
description: "iXML command function: Function definition."
canonical_url: "https://www.zeyos.com/ixml/ref/function"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ref/function.md"
section: "ixml-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/ixmldoc.xml"
source_sha256: "a23f04e6a98628ca3c273c3b8dd2c33c034cfda3e0f00478d8793074fd2f70dd"
---

# function — Function definition

The FUNCTION construct defines a closed subroutine as a code sequence that can be invoked with subsequent CALL statements.

The USE construct declares a free function variable for use as a local variable within the closure function that is explicitly bound to a corresponding variable from the immediate context within which the function is defined, thereby directly referencing the non-local variable from the parent scope outside of the inherent context of the function. The parent scope of the closure is the one in which the function is defined, not necessarily the one that the function was called from.

In the context of object-oriented design, a function that corresponds to an array item is to be termed a method while the referenced array is to be termed an object.

A function can be coded so that it may call itself recursively. This technique allows direct implementation of functions defined by mathematical induction and recursive divide and conquer algorithms.

### Attributes
| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| var | var |  | Variable name |

### Children
- use (occurrence: multiple) — Use

### Parents
- (not restricted in the reference)

### Result
- binding: var; type: function; predicate: no-result-propagation

### Examples

```xml
<global var="name"/>

<function var="outputName">
	<output>$name</output>
</function>

<set var="name">iXML</set>
<call func="outputName"/>

<!-- iXML -->
```

```xml
<function var="outputName">
	<output>$name</output>
</function>

<call func="outputName">
	<param name="name">iXML</param>
</call>

<!-- iXML -->
```

```xml
<set var="obj.name">iXML</set>

<function var="obj.outputName">
	<output>$this.name</output>
</function>

<call func="obj.outputName"/>

<!-- iXML -->
```

```xml
<function var="getName">
	<set var="return">iXML</set>
	<return/>
	<set var="return">XML</set>
</function>

<call func="getName" var="name"/>
<output>$name</output>

<!-- iXML -->
```

```xml
<function var="outputName">
	<output>$name&n;</output>
</function>

<array var="names">
	<item>Bill Gates</item>
	<item>Steve Jobs</item>
</array>

<foreach var="names" var_value="name">
	<call func="outputName">
		<param name="name">$name</param>
	</call>
</foreach>

<!--
Bill Gates
Steve Jobs
-->
```

```xml
<set var="count">1</set>

<function var="output">
	<use var="count"/>

	<output>$count&n;</output>
	<math:inc var="count"/>
</function>

<for from="1" to="5">
	<call func="output"/>
</for>

<!--
1
2
3
4
5
-->
```
