Lab · c01.s02.L1

Recursion tracer

Repeating a step beats a single delegating pass only when the repetition keeps its whole state in a fixed number of values, so it can be paused and resumed.

Question: When does repeating a step beat doing it once?

Recursion tracerTwo panels total twelve charges, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 and 4, and both end at 7. The left panel, in round brackets, opens one waiting addition per row until twelve are stacked, then collapses them from the inside out. The right panel, in square brackets, keeps only a counter and a running total: two numbers on a card, grown left to right. Paused, only the card's two numbers carry on.Rows to total: 12(( delegating pass ))the same twelve rows, one waiting addition each[ repeating step ]a counter and a running totalPause at any move and thiscard is enough to carry on.Both panels add the same twelve rows; only the unfinished work differs.row 10row 20row 31row 40row 50row 61row 71row 80row 90row 100row 110row 124Move 0 of 24 — before the first call12 charges, total 7the delegating expressionno bracket opened yetnot written yetstatenothing yet
Re-simulated Re-simulated: both panels are computed by data/scripts/c01.s02.L1.py from the twelve charges section 1.2 records, and the lab shows only numbers from data/c01.s02.L1.json. The frames step through the delegating expansion and contraction and the running total for the default twelve rows: the waiting stack peaks at 12 additions, while the looping card never holds more than 2 numbers. The drawing is a diagram of the computation, not a timing of a real interpreter.
Lab controls
12 rows

Left/Right step by 1; Page Up/Page Down step by 4; Home sets 1; End sets 12

0 move

Left/Right step by 1; Page Up/Page Down step by 4; Home sets 0; End sets the last move

900 ms per frame

Left/Right step by 100 ms; Page Up/Page Down step by 500 ms; Home sets 300; End sets 1600

Frame 1 of 11: Move 0 — the twelve rowsBefore the first call. The twelve recorded charges sit in row order, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 and 4, and their total is 7. The delegating panel has opened no bracket, and the repeating panel's card has nothing written on it.

Move 0 — the twelve rows. Before the first call. The twelve recorded charges sit in row order, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 and 4, and their total is 7. The delegating panel has opened no bracket, and the repeating panel's card has nothing written on it.

Keyboard: Space plays or pauses, Left and Right step, Home goes to the first frame, End goes to the last frame.

Text description of this lab

Two panels total twelve charges, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 and 4, and both end at 7. The left panel, in round brackets, opens one waiting addition per row until twelve are stacked, then collapses them from the inside out. The right panel, in square brackets, keeps only a counter and a running total: two numbers on a card, grown left to right. Paused, only the card's two numbers carry on.

Return to the section that hosts this lab

Caption status: re-simulated. Every lab declares one of published, re-simulated, schematic, synthetic or interpolated.