0xBUFF / docs

Bindings and references

Explain primitive assignments, heap references, shared mutations, and rebinding with the bindings domain.

Version scope — v0.0.2 (historical schema 1). This page and its examples use @0xbuff/throughline@0.0.2, the version pinned by this documentation app. They do not describe the unreleased schema-2 API intended for v0.2.0. See compatibility and upgrading.

The bindings domain visualizes a small, intentionally restricted assignment language. It shows variable slots in a Stack lane and arrays/objects in a Heap lane. Use it to explain the difference between copying a primitive and copying a reference.

It is not a JavaScript interpreter: it supports only declarations, assignments, and array push. Expressions, property access, branching, and arbitrary method calls are not supported.

Example: two names, one array

```thl bindings
let list = [1, 2]
let alias = list
alias.push(3)
alias = [7]
```

This produces four authored beats plus the initial frame:

  1. list receives a reference to the first heap array, o1.
  2. alias receives the same reference; the array is not cloned.
  3. alias.push(3) mutates o1. Both list and alias still refer to the changed array.
  4. alias = [7] creates a new heap object, o2, and moves only the alias reference. list still points to o1.

Heap nodes and reference edges are predeclared hidden and revealed as needed. Previous references are hidden when rebinding changes the pointer, but old objects remain available for other aliases.

Watch two references share an array

Step through copying a reference, mutating the array, and moving one pointer.

Loading the interactive player…
View trace source
thl bindings
let list = [1, 2]
let alias = list
alias.push(3)
alias = [7]

Follow the links in each frame: after the push, both names still point to the same array. The final assignment moves only the alias reference.

Accepted statements

StatementDescription
let name = <json>Declare a variable with a JSON literal
const name = <json>Same visualization as let; const restrictions are not enforced
let name = existingDeclare a new variable copying an existing primitive or reference
const name = existingSame copying semantics; const restrictions are not enforced
name = <json>Reassign a previously declared variable
name = existingCopy an existing variable into a previously declared variable
name.push(value1, value2)Append JSON values to an array referenced by the variable

Use one statement per source line. Blank lines and whole-line # comments are ignored; each non-comment statement becomes exactly one beat.

Right-hand-side literals must be valid JSON. Strings require double quotes. A bare identifier refers to a previously declared variable.

Primitive copy

```thl bindings
let a = 5
let b = a
b = 9
```

Each primitive occupies its own variable slot. Assigning b does not mutate a.

Object reference copy

```thl bindings
const configuration = {"ready":true}
let other = configuration
other = {"ready":false}
```

Objects, like arrays, are allocated in the heap and copied by reference. This domain does not support changing object properties; rebinding to a new object is supported.

Push to a shared array

```thl bindings
let a = []
let b = a
b.push(1, 2, 3)
```

The array receives three appended values. The visualization focuses the object and other names sharing that object.

Boundaries and common mistakes

  • A variable must be declared before use; duplicate declarations fail.
  • A push receiver must be a variable currently holding an array reference. Pushing to a primitive or object fails.
  • Bracket indexing (a[0]), object property assignment (a.x = 2), pop, arithmetic, functions, and JavaScript expressions are not supported.
  • const is syntax for declaration only. Do not teach this domain as an accurate JavaScript const-enforcement simulator.
  • Future nodes may exist in a trace while hidden. They are not visible current state.
  • The general compiler event, size, and work limits still apply.

For fully hand-authored custom pointer changes, use flow instead.

On this page