B2.4 · dive 1 — archetypes are data
A row, a reference, a map.
An archetype is data: an entity under the newly registered ARC namespace whose value is a property bundle, extending at most one parent. An instrument is a reference plus overrides. The composed view is a pure fold — bundles folded root-first, overrides applied last, right-most wins.
Source: content/bcs2.4.md, quoting bcs_rung_2_4_check.out; the resolver
is committed at runtimes/elixir/lib/echo_data/bcs/archetypes.ex.
tick 0.25 from the instrument,
settlement :daily_mark from the archetype, margin true from the base: three sources, one map,
no ambiguity about who wins.The transcript
bcs_rung_2_4_check.out · verbatim · this dive reads boot and A1boot: the registry grows by one -- ARC, archetype definitions as rows A1 order ok -- composition order proven: tick 0.25 from the instrument, settlement :daily_mark from the archetype, margin true from the base A2 amplify ok -- one definition edited, a thousand instruments follow: multiplier 100 at next read; an instrument row is 18 words, its composed view 14 A3 guard ok -- the diamond is unrepresentable (one :extends) and the cycle is refused: {:error, :cycle}; depth capped at 8: {:error, :depth} A4 rows ok -- archetypes are rows: an AST name refused with {:error, :namespace}; ARC pages newest-first like any property A5 cost ok -- read-time composition over a depth-2 chain: store-lane 5442 ns/op vs snapshot-lane 1048 ns/op; a bare row get is 2653 ns/op PASS 5/5
The model
content/bcs2.4.md · WhatAn archetype bundle lives in the :archetypes store under ARC;
it may carry :extends naming one parent. An instrument row carries archetype:
(the reference) and overrides: (the deltas). The composed view is
compose(chain, overrides) — bundles folded root-first, overrides applied last, right-most
wins — produced by a resolver that is pure by construction: it takes a fetch function, so the same walk
runs against a store boundary or a snapshot, and the fetch-function seam doubles as the test seam.
No behaviour modules, no protocol dispatch on kind, no hierarchy of code anywhere in
the design. A1 builds the working chain — the derivative base (margin: true, settlement: :t1,
tick: 0.01), a future extending it (settlement: :daily_mark, multiplier: 50), and
the ESZ6 instrument overriding tick — and gates the exact view: tick 0.25 from the instrument,
settlement :daily_mark from the archetype, margin true from the base.
The fold, in Elixir and in Go
content/bcs2.4.md · How · lib/echo_data/bcs/archetypes.exThe whole mechanism is four lines, and pure:
def compose(chain, overrides) when is_list(chain) and is_map(overrides) do
chain
|> Enum.reduce(%{}, &Map.merge(&2, &1))
|> Map.merge(overrides)
|> Map.delete(:extends)
end
The walk above it carries the seen-set and the depth cap; the store's own gate supplies
a guard the resolver does not re-implement — an :extends pointing outside ARC
meets the archetype store's namespace refusal before any bundle loads. The Go counterpart — the same
fold, the same one-:extends law, over the owner's map:
func Compose(chain []map[string]any, over map[string]any) map[string]any {
out := map[string]any{}
for _, b := range chain {
maps.Copy(out, b)
}
maps.Copy(out, over)
delete(out, "extends")
return out
}
%{} → merge the base → merge the future archetype
→ merge the ESZ6 overrides → drop :extends — four properties out, matching
A1's gated view.The chain arrives root-first, so each merge lets the later bundle win; the
overrides merge last and win over everything; :extends is bookkeeping, not a property,
and the final Map.delete keeps it out of the view.
The ARC registration as a governance act
content/bcs2.4.md · DecisionsArchetypes are entities. The registry grows by one: ARC, archetype
definitions, platform scope — recorded as a decision because registration is the governance act Chapter
1.2 said it is. The boot line carries it verbatim: boot: the registry grows by one -- ARC,
archetype definitions as rows. A namespace registers when a kind needs identity and lifecycle of
its own, and definitions qualified because they are edited, audited, and one day replayed.
Definitions live in the :archetypes property store today — the store
family Property Stores on ETS (B2.2) built — and in the
forest of The CHAMP Property Database (B2.3) the day history is
asked for; same key, both homes.
References
sources · relatedSources
- West — Evolve Your Hierarchythe component turn; entities as data, behavior composed
- Venners — Design Principles from Design PatternsGamma on composition over inheritance, defended a decade on
Related
- B2.4 — Archetypes and Compositionthe module hub; the full rung in context
- B2 — The Elixir BCS Corethe chapter landing; the Part II arc
- B2.2 — Property Stores on ETSthe store family the :archetypes store belongs to
- B1 — Ideas Behindthe law and the identity contract
- Functional Programming in Elixirthe umbrella where echo_data lives