This is a program to illustrate where nested procedures are of use but especially where two different procedures exist at once with the same code body. They are objects implemented as procedures.
The hack is to run the double instance algorithm while the two abstracted instances are each separately on the stack. After the answer is reported we are done with the machines and the stack dissolves.
Pascal and PL/I would do this nicely too. This can be done in Java and C++ but only in a different style. Here is another application.