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

# macro — Macro definition

The MACRO construct defines an open subroutine as a code sequence that can be expanded with subsequent EXPAND statements.

Macro expansion allows for code reuse with minimal computational overhead compared to function invocation.

A macro can be coded so that it may expand 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
- (none)

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

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

### Examples

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

<set var="name">iXML</set>
<expand macro="outputName"/>

<!-- iXML -->
```

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

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

<foreach var="names" var_value="name">
	<expand macro="outputName"/>
</foreach>

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