# Containers, not collections

The standing constraint that DS
provides containers and does not provide collections, and
the gate every proposal introducing or extending a data
grouping must pass. Zero grammar surface — this doc
constrains what may be added to the language, not what the
language already spells.

Paired with:

- [LSCO] — the narrow surface this doc
  generalises to every data grouping.
- [LDET] — the bounded-cost
  requirement one of these rejections falls out of.
- [LEXP] — `Json`, a
  container whose surface the doctrine shaped.
- [LSER] — series and signals, the other
  container: closed aggregations, no per-sample access.
- [LCRS] — the adapter
  boundary iterative logic is pushed across.

(LCNT-1)=
## The rule [LCNT.1]

(LCNT-1-1)=
[LCNT.1.1] A **container** is a value-typed data grouping the author
operates on as a whole, through a closed, fixed, bounded-cost algebra.
The author asks a container questions and applies closed operations to
it; the author never enumerates its contents.

(LCNT-1-2)=
[LCNT.1.2] A **collection** is a data grouping the author traverses
element by element — with a cursor, a loop, a comprehension, or an
author-supplied `map` / `filter` / `reduce`.

(LCNT-1-3)=
[LCNT.1.3] DS must provide containers ([LCNT.1.1]) and must not provide
collections ([LCNT.1.2]). A construct that hands the rule author a way
to traverse a grouping's contents must be rejected whatever its other
merits. This is a standing constraint on the language, not a preference
weighed per feature.

*see also:* [LCNT.1.1](#LCNT-1-1), [LCNT.1.2](#LCNT-1-2)

(LCNT-2)=
## The gate [LCNT.2]

(LCNT-2-1)=
[LCNT.2.1] One question decides whether a data grouping is admissible
([LCNT.1.3]):

> **Does it expose iteration, a cursor, or data-dependent traversal of
> its contents to the rule author?**

If it does, it is a collection and is rejected. If instead it offers a
fixed algebra — membership, static projection, reduction, or a closed
transform ([LCNT.3.1]) — over a well-typed grouping, it is a container.

*see also:* [LCNT.1.3](#LCNT-1-3), [LCNT.3.1](#LCNT-3-1)

(LCNT-2-2)=
[LCNT.2.2] A container is opaque to walking and transparent to algebra.
That is the observable consequence of [LCNT.1.3]: because the language
exposes no traversal surface, the only operations an author can apply
are the closed ones the algebra names.

*see also:* [LCNT.1.3](#LCNT-1-3)

(LCNT-2-3)=
[LCNT.2.3] Applying the gate to a concrete proposal: name the closed
operations the grouping offers, confirm each is bounded-cost, and
confirm none hands the author a way to iterate. Where the proposal's
value *is* iteration, it belongs across the adapter boundary
([LCNT.6.1]), not in the language.

For signal processing the same question reads: which fixed transform or
reduction — and which incremental backing realises it — joins the
algebra? Never: how does an author walk samples?

*see also:* [LCNT.6.1](#LCNT-6-1)

(LCNT-3)=
## What the gate admits [LCNT.3]

(LCNT-3-1)=
[LCNT.3.1] The four operation classes a container algebra may offer.
Each keeps the grouping opaque to walking ([LCNT.2.2]).

| Class | Admitted because | v1 instances |
|---|---|---|
| Membership / cardinality | answers a question *about* the grouping without yielding an element | `contains(cursor, value)`, `count` over a declared window, `has(j.path)`, `len(j)` |
| Static projection | the name, key, or index is fixed at author time, so the cost is constant and the path is inspectable | `json.a.b[0]` |
| Reduction | collapses the grouping to a scalar by a fixed aggregation | `mean`, `pXX`, `integral`, structural equality |
| Closed transform | a fixed grouping-to-grouping operation, computed incrementally over a declared window | the series aggregations ([LSER.18.1]) |

An index computed by a loop is not a static projection, and no v1
construct produces one.

*see also:* [LCNT.2.2](#LCNT-2-2), [LSER.18.1](#LSER-18-1)

(LCNT-4)=
## What the gate rejects [LCNT.4]

(LCNT-4-1)=
[LCNT.4.1] The language must not grow any of the following:

- `for each`, loops, cursors, or iterators over a grouping's contents;
- list, array, or map types whose purpose is sequential traversal;
- comprehensions, or `map` / `filter` / `reduce` taking an
  author-written lambda;
- any operation whose cost is data-dependent and unbounded.

Each is a collection surface by [LCNT.1.2], and [LCNT.1.3] forecloses
it. The last also fails the bounded-cost requirement independently
([LCNT.5.2]).

*see also:* [LCNT.1.2](#LCNT-1-2), [LCNT.1.3](#LCNT-1-3), [LCNT.5.2](#LCNT-5-2)

(LCNT-5)=
## Why the language holds this line [LCNT.5]

The constraint is not aesthetic. It falls out of three commitments DS
has already made.

(LCNT-5-1)=
- [LCNT.5.1] **Declarative, not procedural.** DS is Rete
  pattern-match-and-react ([LSCO.4.5.9]). Rules fire on matches; they do
  not loop. The only iteration in the system is the engine's match loop —
  engine-driven, bounded by the fact base, and never authored.

*see also:* [LSCO.4.5.9](#LSCO-4-5-9)

(LCNT-5-2)=
- [LCNT.5.2] **Bounded, predictable cost.** The determinism guarantee
  ([LDET.1.1]) and the `realtime` / `constspace` capabilities require
  every operation to be a total function of bounded cost — `O(1)` or
  `O(declared window)` — usually realised incrementally. Iteration
  injects unbounded, data-dependent time.

*see also:* [LDET.1.1](#LDET-1-1)

(LCNT-5-3)=
- [LCNT.5.3] **Replayable and debuggable.** A closed algebra is
  deterministic and testable by construction. A mutable iteration
  accumulator is neither.

(LCNT-5-4)=
[LCNT.5.4] **The rule binds the author surface, not the
implementation.** The runtime iterates constantly — the match loop,
bounded scans, incremental aggregation — and must remain free to.
[LCNT.1.3] constrains what the language exposes to the *rule author*:
the author must never write a loop or hold a cursor. A proposal must not
be rejected under [LCNT.2.1] on the ground that its implementation
iterates.

*see also:* [LCNT.1.3](#LCNT-1-3), [LCNT.2.1](#LCNT-2-1)

(LCNT-6)=
## The escape valve [LCNT.6]

(LCNT-6-1)=
[LCNT.6.1] [LCNT.1.3] does not say DS cannot iterate. Genuinely
iterative, imperative, or stateful logic must go out to an adapter — a
`call` to an external service ([LCRS]) —
fenced at that boundary and recorded as facts for deterministic replay.
Iteration happens outside the deterministic core, never inside the rule
language.

A gap in the fixed algebra must be filled either by adding a closed
operation to it ([LCNT.3.1]) or by pushing the work across the adapter
boundary. It must not be filled by opening iteration.

*see also:* [LCNT.1.3](#LCNT-1-3), [LCNT.3.1](#LCNT-3-1)

(LCNT-7)=
## The doctrine in the v1 containers [LCNT.7]

Neither grouping v1 ships exposes an element to the author.

(LCNT-7-1)=
- [LCNT.7.1] **`Json`** offers static path projection (`a.b[0]`),
  `has(j.path)`, `len(j)`, and structural equality with no ordering
  ([LEXP.7.19]). It offers no element
  enumeration, which is why `Json` is the opaque-payload fallback rather
  than a list type ([LEXP]).

*see also:* [LEXP.7.19](#LEXP-7-19)

(LCNT-7-2)=
- [LCNT.7.2] **Series and signals** offer windowed aggregations computed
  by incremental streaming backings — Welford, ring buffer, monotonic
  deque, FIFO deque, reservoir ([LSER.18.1]). The author declares what to
  compute and reads the result; the author gets no per-sample access, and
  never names a backing ([LSER.13.3]).

*see also:* [LSER.13.3](#LSER-13-3), [LSER.18.1](#LSER-18-1)

