R/MRatCalcpowered by RiX

RiX walkthrough 7 d

Capstone: shared ledger

Use cells, destructuring, and updates in a small model.

The problem

A tiny ledger entry contains an account and an amount. A live balance and a display binding should intentionally share updates, while an archived value should remain independent. This is a compact demonstration of why RiX has several assignment forms.

Prerequisites: Cells and assignment, Destructuring, and Maps. Predict the displayed and archived balances before running the cell.

Build the solution

Runnable RiX

How the pieces fit

Destructuring extracts the map entries. The display name aliases balance because plain equals shares a cell. The archive uses fresh-copy assignment, so it keeps the earlier value. Updating balance therefore changes display but not archive. The final tuple makes the contrast easy to inspect.

Trace identity, not only value

When the snapshot is created, it prints the same number as the live balance, yet the names mean different things. An alias follows updates to the shared cell; a fresh value records history. A ledger needs both: the live account answers what is true now, while the snapshot supports audit.

Destructuring gives the transaction a readable boundary instead of scattering positional lookups through the update. Inspect alias, snapshot, and balance individually after running the cell. Their differing behavior makes RiX identity observable even when two printed values began equal.

The choice between = and := is the point of this model: one name follows the live balance, while the other preserves an earlier value.

Extend the model

Once the first version works, change one input and observe which outputs change. Then add one intermediate name so the next reader can inspect the new rule without mentally executing the entire program.

Review questions

  • What are display and archive after the half-unit update?
  • Which assignment made display share the balance's cell?
  • What changes if the archive uses = instead of :=?