Engineering / Language interpreter implementation
The little debugger
Trace shared variables, function calls, and a branch whose changes must roll back.
Repair two rules in a tiny language machine. An alias names the same cell. A rejected branch must undo both its mutations and its printed output. The accepted branch should finish with x = y = 6 and print just 6.
Eight-line program
- 1
let x = 2 - 2
alias y = x - 3
define bump(): x = x + 3 - 4
try: bump(); print x - 5
reject that trial - 6
accepted: y = y + 1 - 7
accepted: bump() - 8
accepted: print x
Live memory
Create x = 2
1 / 8
Make a change, explore the result, then check your solution.
Need a hint?
Point y at x’s existing cell and restore all cells, aliases, and output on rejection. At line 5, both values return to 2 and the trial’s printed 5 disappears.