The same expression can stop meaning the same computation.
Expose history dependence, order dependence, and alias-sensitive observations that appear when procedure calls can change remembered locations.
Which substitution and reordering arguments become invalid once an expression can mutate state?
- Compare repeated stateful calls with repeated pure calls
- Recognize that equal source expressions can produce different values over time
- Make two evaluation schedules explicit instead of relying on operand order
- Observe how one earlier call changes the meaning of a later call
- Record the exact finite schedule and its evaluation order
Two calls to the same withdraw procedure with the same argument return 90 and then 80 because the first call changes the captured balance. Replacing both calls with one previously computed value would therefore change the program. The pure withdraw-value procedure has no hidden history, so two calls from the same explicit balance both return 90.
The order probe makes schedule dependence explicit with let bindings. Calling the zero message first changes state before the one message reads it. Calling one first observes the old state. No conclusion here depends on the evaluator choosing an operand order; the two sequences are written separately and compared as data.
- Output
- —
- Value
- —
- Diagnostic
- —
The repetition program returns (90 80 90 90). The explicit schedules return ((0 1 1) (0 0 0)).
Find the balance assignment between the two identical stateful calls, then confirm that the pure calls allocate no persistent location. In the schedule comparison, follow the first call before the second and identify the exact read whose value changes.
Change the program and compare the result.
Add a reset message to the order probe and compare zero–reset–one with zero–one–reset. Explain which algebraic replacement or call reordering would change each observation.
Show hint
Write every call in a nested let so the schedule is part of the source rather than an assumption about argument evaluation.