TAOCP 1.4.2 Exercise 1
A coroutine requires at least two control contexts that repeatedly suspend and resume execution at interior points, together with a mechanism for preserving the point of suspension.
Exercise 1. [10] Explain why short, simple examples of coroutines are hard for the author of a textbook to find.
Verified: yes
Solve time: 38s
A coroutine requires at least two control contexts that repeatedly suspend and resume execution at interior points, together with a mechanism for preserving the point of suspension. Even in the smallest MIX implementation this forces explicit linkage storage (such as saving $J$ into a cell like AX or BX) and explicit re-entry logic, so a minimal example already contains the same structural machinery as a full example. The overhead of state saving and transfer of control therefore occupies a substantial fraction of any correct program, preventing reduction to a genuinely short fragment.
If the computational content is reduced further, the interaction degenerates either into an ordinary subroutine call pattern or into a single linear routine with no suspension points. Nontrivial coroutine behavior requires staged production and consumption of data, such as the alternating generation and transformation in the input–output example of the section, and this type of interaction necessarily introduces multiple steps and control transfers that cannot be compressed without losing the coroutine structure. This combination of required linkage and required interaction forces even the simplest correct illustrations to remain relatively long. ∎