Shared structure makes mutation visible at a distance.
Two paths can lead to the same pair. Mutating that pair through either path changes what both paths observe.
Why is shared identity different from merely equal contents?
- Distinguish one shared object from two equal objects
- Predict the effect of mutation through an alias
- Read shared references in a graph-shaped result
tree stores shared in both its car and cdr. There is one inner pair and two references to it, not two copied lists. set-car! therefore changes the object reached from both sides.
The printed #0= label introduces the shared object and #0# refers to that same object again. The labels preserve identity that ordinary list notation would hide.
- Output
- —
- Value
- —
- Diagnostic
- —
The first program returns (#0=(changed) . #0#).
Look for one allocation of the shared inner pair and one later mutation. The result graph keeps both references attached to the same object identity.
Change the program and compare the result.
Run the separate-pairs example and compare its result. Explain why changing left does not change right even though both began with equal contents.
Show hint
Count allocations, not printed leaf symbols.