---
title: "reference-book/Gates"
source: reference-book
version: genesis-0-1-0
id: reference-book/Gates
canonical: /docs/reference-book/Gates
---

When a single variable is not enough, **Gates** combine multiple events into a more complex structure or logic.

A **Gate** is a Shell type that acts as an event aggregator — it collects events from multiple slots and releases them according to a condition. After a Gate releases, it is cleared.

Simorg provides two Gate types, each with its own syntax and behavior:

| Gate | Syntax | Releases when |
|------|--------|---------------|
| OR | <<<[ ]>>> | at least one slot has an event |
| AND | <<<( )>>> | every slot has an event |

### OR

Use <<<[ ]>>> to define an OR gate. It releases when **at least one** slot receives an event.

```
[1,2,3] ? // [1,2,3]
```

Three value literals fire at startup; the OR gate receives them and releases because at least one slot is active. The logger prints the result in gate form.

The engine aggregates events when possible — all three values appear together in one release.

Empty values (<<<0>>>, <<<"">>>, <<<0x>>>, <<<0.0>>>) are valid events. Gates respond to **event presence**, not truthy/falsy checks. Guards for empty values are covered later in the Event Flow chapter.

### XOR

Same bracket syntax, but separate slots with <<<;>>> instead of <<<,>>> to get **sequential** release — one event per processing cycle.

```
[1;2;3] ? // 1
          // 2
          // 3
```

Unlike OR, XOR does not batch: each slot releases one at a time. This makes XOR useful when events must flow in sequence.

Simorg is fully async — events decide what goes next, not line order.

### AND

Use <<<( )>>> to define an AND gate. It releases only when **all** slots have an event.

```
100 $var1
"hello" $var2
0.0 $var3

(var1, var2, var3) $myAndGate
myAndGate ? // (100, hello, 0.0)
```

If any slot is missing an event, the gate does not release:

```
100 $var1
"hello" $var2
$var3

(var1, var2, var3) $myAndGate
myAndGate ? // nothing logged
```

Use <<<,>>> to separate slots in an AND gate. <<<;>>> has no effect here.

### Key Takeaways

Gates behave like logical gates in software and electronics. What matters is whether a slot has an event, not whether its value is <<<truthy>>>. Values like <<<"">>>, <<<0>>>, and <<<0x00>>> are valid events.

Beyond holding data, Gates define **dependencies** between events. An AND gate states that certain fields must arrive together:

```
"Jacob" $name
21 $age
"Istanbul" $city

(name, age, city) $userInformation
```

Whenever <<<userInformation>>> releases, <<<name>>>, <<<age>>>, and <<<city>>> are guaranteed to be present together.

### Scope

variables declared inside a gate belong to that gate's scope. Access named slots with the <<<.>>> operator:

```
(
  "HELLO" $hello,
  "BYE" $bye
) $message

message.hello ? // HELLO
```

Gates blend object and array behavior: named slots are accessed like object fields; reading the gate as a whole treats it like a collection. More on this in the Wrapper Shells chapter.
