ArticleslgStudy

computer science

Man or boy test

Man or boy test is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Man or boy test rather than just read about it. In short: The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguish compilers that correctly implemented "recursion and non-local references" from those that did not.

Key takeaways

  • Man or boy test belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Man or boy test to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Man or boy test from memory before moving on to harder problems.

Reference excerpt

The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguish compilers that correctly implemented "recursion and non-local references" from those that did not.

There are quite a few ALGOL60 translators in existence which have been designed to handle recursion and non-local references properly, and I thought perhaps a little test-program may be of value. Hence I have written the following simple routine, which may separate the man-compilers from the boy-compilers.

Knuth's example 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).

Explanation There are three Algol features used in this program that can be difficult to implement properly in a compiler:

Nested function definitions: Since B is being defined in the local context of A, the body of B has access to symbols that are local to A — most notably k, which it modifies, but also x1, x2, x3, x4, and x5. This is straightforward in the Algol descendant Pascal, but not possible in the other major Algol descendant C (without manually simulating the mechanism by using C's address-of operator, passing around pointers to local variables between the functions). Function references: The B in the recursive call A(k, B, x1, x2, x3, x4) is not a call to B, but a reference to B, which will be called only when k is greater than zero. This is straightforward in standard Pascal (ISO 7185), and also in C. Some variants of Pascal (e.g. older versions of Turbo Pascal) do not support procedure references, but when the set of functions that may be referenced is known beforehand (in this program it is only B), this can be worked around. Constant/function dualism: The x1 through x5 parameters of A may be numeric constants or references to the function B — the x4 + x5 expression must be prepared to handle both cases as if the formal parameters x4 and x5 had been replaced by the corresponding actual parameter (call by name). This is probably more of a problem in statically typed languages than in dynamically typed languages, but the standard workaround is to reinterpret the constants 1, 0, and −1 in the main call to A as functions without arguments that return these values. 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.

See also Funarg problem Jensen's device

References

External links Man or boy test examples in many programming languages

Worked examples

Example 1 — a first encounter with Man or boy test

Start with the simplest possible case. Write down what Man or boy test claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Man or boy test before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Man or boy test ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Man or boy test

In research
Man or boy test appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Man or boy test in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Man or boy test is common in secondary-school and first-year university syllabi. It links to neighbouring topics ALGOL 60 implementation, Compiler construction, Computer-related introductions in 1964, so understanding it makes those chapters shorter.
In everyday life
Look for Man or boy test outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Man or boy test in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Man or boy test means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Man or boy test out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Man or boy test in simple terms?

The man or boy test was proposed by computer scientist Donald Knuth as a means of evaluating implementations of the ALGOL 60 programming language. The aim of the test was to distinguish compilers that correctly implemented "recursion and non-local references" from those that did not.

Why does Man or boy test matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Man or boy test?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Man or boy test.

Tags

  • ALGOL 60 implementation
  • Compiler construction
  • Computer-related introductions in 1964
  • Donald Knuth
  • Programming language design
  • Programming language folklore
  • Test items in computer languages

Keep exploring