---
title: "Variables"
description: "Variable operations — set, unset, null/true/false, assign, clone, swap, cast, eval, verbatim, global."
canonical_url: "https://www.zeyos.com/ixml/ixml-guide/syntax-essentials/variables"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ixml-guide/syntax-essentials/variables.md"
section: "ixml-guide"
authority: "guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/ixml/04-syntax-essentials/variables.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Variables

## `set` — Set variable

The most fundamental command in iXML. Assigns a string value to a variable, creating it if it doesn't exist. The value is **always of type `string`** unless replaced by an embedded statement via result propagation.

```xml
<set var="firstname">Bill</set>
<set var="lastname">Gates</set>
<output>$firstname $lastname</output>
<!-- Bill Gates -->
```

Setting array items — these three forms are equivalent:

```xml
<set var="names[bg]">Bill Gates</set>
<set var="names.sj">Steve Jobs</set>
<set var="names" key="le">Larry Ellison</set>
```

Auto-increment key with empty brackets:

```xml
<set var="list[]">first</set>
<set var="list[]">second</set>
```

[Full reference →](https://www.zeyos.com/ixml/ref/set)

---

## `unset` — Remove variable

Removes a variable entirely, making it `undefined`. Different from setting to `NULL` or empty string.

```xml
<set var="x">hello</set>
<unset var="x"/>
<!-- typeof is now 'undefined' -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/unset)

---

## `null` / `true` / `false` — Set typed values

Set a variable to a specific typed value directly:

```xml
<null var="x"/>    <!-- type: null -->
<true var="flag"/> <!-- type: bool, value: TRUE -->
<false var="off"/> <!-- type: bool, value: FALSE -->
```

[`null`](https://www.zeyos.com/ixml/ref/null) | [`true`](https://www.zeyos.com/ixml/ref/true) | [`false`](https://www.zeyos.com/ixml/ref/false)

---

## `assign` — Type-preserving assignment

Copies a value from one variable to another, preserving the original data type. Complex types (arrays, functions) are assigned **by reference**.

```xml
<set var="name1">iXML</set>
<assign var="name2" var_source="name1"/>
<output>$name2</output>
<!-- iXML -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/assign)

---

## `clone` — Independent copy

Creates a **shallow copy** independent of the original. Essential for arrays where `assign` would create a shared reference.

```xml
<array var="original">
    <item>Bill Gates</item>
    <item>Steve Jobs</item>
</array>

<clone var="original" var_result="copy"/>
<set var="copy[1]">Larry Ellison</set>

<output>$original[1] and $copy[1]</output>
<!-- Steve Jobs and Larry Ellison -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/clone)

---

## `swap` — Exchange two variables

Exchanges values in a single atomic step:

```xml
<set var="a">first</set>
<set var="b">second</set>
<swap var1="a" var2="b"/>
<output>$a, $b</output>
<!-- second, first -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/swap)

---

## `cast` — Type conversion

Converts a variable to a specified data type. Essential because `<set>` always creates strings.

```xml
<set var="number">123</set>
<cast var="number" type="int"/>

<is var="number" type="int">
    <output>$number is now an integer!</output>
</is>
```

Supported types: `bool`, `int`, `float`, `string`. See [Type Conversion](https://www.zeyos.com/ixml/ixml-guide/data-types/type-conversion) for conversion rules.

[Full reference →](https://www.zeyos.com/ixml/ref/cast)

---

## `eval` — Evaluate expression

Evaluates a string with variable substitution, resolving references dynamically:

```xml
<set var="dollar">$</set>
<set var="name">iXML</set>

<output>
    <eval>My name is $dollar$name!</eval>
</output>
<!-- My name is iXML! -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/eval)

---

## `verbatim` — Prevent substitution

Returns content **without** variable substitution — the opposite of `eval`:

```xml
<output>
    <verbatim>Show me the $dollars!</verbatim>
</output>
<!-- Show me the $dollars! -->
```

[Full reference →](https://www.zeyos.com/ixml/ref/verbatim)

---

## `global` — Declare global variable

Declares a variable with global scope, visible across all contexts including functions and includes:

```xml
<global var="appName"/>
<set var="appName">MyApp</set>

<function var="showName">
    <output>$appName</output>
</function>

<call func="showName"/>
<!-- MyApp -->
```

Use sparingly — prefer passing data as parameters.

[Full reference →](https://www.zeyos.com/ixml/ref/global)
