v3 Language: Collections and Closures

  • Track aliases and closure environments across function return.
  • Identify v3 lexical additions without assigning them parser meaning.
  • Distinguish primitive values from VM heap objects.
1 / 6

Readiness

  • Pass the v2 integration gate and understand source-order binding.
2 / 6

Worked reconstruction

Trace the value graph for:

fn make(start) {
  var n = start;
  fn next() { n = n + 1; return n; }
  return next;
}
let counter = make(4);
let a = counter();
let b = counter();

The call to make creates environment E with start=4 and n=4. Creating next allocates a closure that refers to its code ID and E. Returning the closure keeps E reachable after make's call frame ends. The first counter call creates a new parameter environment whose parent is E, updates E.n to 5, and returns 5. The second updates the same binding to 6. Copying n=4 into each call would yield 5 twice and fail the shared-binding contract.

3 / 6

Diagnose before implementing

A returned counter closure observes the caller’s local n=100 instead of its defining n=4. What parent environment was chosen incorrectly? Would preserving only the function ID fix it?

4 / 6

Independent transfer

Create two counters from make(4). Predict interleaved calls A, A, B, A and draw which environment each closure retains. Then tokenize a map whose value is an array without interpreting either container.

5 / 6

Carry forward

Carry the value graph and new punctuation into v3 parsing. Preserve source-order evaluation and shared-binding examples for the VM and GC stages.

6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen