> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Expressions

> Operators, ternary, match, f-strings, heredocs, and resource for/when modifiers in XCL.

XCL supports a rich set of expressions for computing values in `locals` blocks, resource properties, and `output` values.

## Literals

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
"hello"          // string
42               // int
3.14             // number (float)
true             // bool
false            // bool
null             // null
```

## Operators

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
x + y   x - y   x * y   x / y   x % y      // arithmetic
x == y  x != y  x < y   x > y   x <= y  x >= y   // comparison
x && y  x || y  !x                          // logical
value ?? fallback                            // null coalescing
```

`??` returns `fallback` when `value` is `null`.

## Access and calls

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
a.b            // member access
a[i]           // index
a[*]           // splat (all elements)
f(x, y)        // function call
@networking.vpc_id   // cross-stack output
secret("env", "TOKEN")  // secret expression
```

## f-strings

Interpolated strings use the `f"…"` form with `{expr}` placeholders:

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
f"{input.env}-{input.project}-data"
f"https://{host}/api"
```

## Heredocs

Multi-line strings use `<<EOT`; `<<-EOT` trims leading indentation. Prefix with `f` for interpolation (`f<<EOT` / `f<<-EOT`):

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
policy = <<EOT
{
  "Version": "2012-10-17",
  "Statement": []
}
EOT

greeting = f<<-EOT
  Hello, {input.name}!
EOT
```

## Ternary

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
value if condition else fallback
```

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
instance_class = "m5.large" if input.env == "prod" else "t3.micro"
```

Ternaries chain and may be used directly in resource properties.

## Match

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
match subject {
  "prod":    "db.m5.large"
  "staging": "db.t3.medium"
  default:   "db.t3.micro"
}
```

`default` is a required catch-all. Match subjects can be strings or integers, and a `match` may be used directly in a resource property.

## Resource for / when modifiers

Resources support two modifiers. `for … in …` fans a resource out over a list or map; `when` includes it conditionally. They are written **inside the block body, at the top, before any property assignments** and separated from the properties by a blank line. They can be combined, and `for` supports a `k, v` map form.

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
// One subnet per CIDR
subnets = aws.ec2.Subnet {
  for cidr in input.subnet_cidrs

  vpc_id     = vpc.id
  cidr_block = cidr
}

// Map iteration
records = aws.route53.Record {
  for name, ip in input.hosts

  name = name
  ttl  = ip
}

// Conditional creation
nat = aws.ec2.NatGateway {
  when input.enable_nat

  subnet_id = public_subnet.id
}

// Combined, with a filter
endpoints = aws.ec2.VpcEndpoint {
  for svc in input.services
  when svc.enabled

  service_name = svc.name
}
```

The pre-`{` header form (`Type for x in list when cond {`) is also accepted by the parser, but `ubx fmt` rewrites it to the inside-the-block form shown above.

## Function calls

```xcl theme={"theme":"css-variables","languages":{"custom":["/languages/xcl.json"]}}
len(input.azs)
upper(input.env)
join(",", input.azs)
cidrsubnet(input.vpc_cidr, 8, 2)
```

See [Built-in functions](/v1/xcl/language/builtin-functions) for the full list.
