In ALGOL 60:
This creates a tree of B call frames that refer to each other and to the containing A call frames, each of which has its own copy of k that changes every time the associated B is called. Trying to work it through on paper is probably fruitless, but for k = 10, the correct answer is −67, despite the fact that in the original article Knuth conjectured it to be −121. Even modern machines quickly run out of stack space for larger values of k, which are tabulated below (OEIS: A132343).
There are three Algol features used in this program that can be difficult to implement properly in a compiler:
These things are, however, not what the test is about; they are merely prerequisites for the test to at all be meaningful. What the test is about is whether the different references to B resolve to the correct instance of B — one that has access to the same A-local symbols as the B that created the reference. A "boy" compiler might, for example, instead compile the program so that B always accesses the topmost A call frame.
Ardö, Anders; Philipson, Lars (March 1984). "A simple Ada compiler invalidation test". ACM SIGAda Ada Letters. III (5): 69–74. doi:10.1145/998382.998385. ISSN 1094-3641. https://doi.org/10.1145%2F998382.998385 ↩
Donald Knuth (July 1964). "Man or boy?". ALGOL Bulletin. 17: 7. "AB17.2.4 Donald Knuth: Man or boy?, page 7". archive.computerhistory.org. See also: "Algol Bulletin". Computing at Chilton: 1961–2000. Retrieved Dec 25, 2009. https://dl.acm.org/doi/10.5555/1060969.1060972 ↩
Wichmann, B. A. (1972-02-01). "Five ALGOL Compilers". The Computer Journal. 15 (1): 8. doi:10.1093/comjnl/15.1.8. ISSN 0010-4620. https://academic.oup.com/comjnl/article-lookup/doi/10.1093/comjnl/15.1.8 ↩