Gödel, Escher, Bach An Eternal Golden Braid by Douglas R. Hofstadter

(Dana P.) #1

scrutiny. A procedure is defined, having one input parameter, N; its output is
the desired value.
This procedure definition has what is called block structure, which
means that certain portions of it are to be considered as units, or blocks. All
the statements in a block get executed as a unit. Each block has a number
(the outermost being BLOCK 0), and is delimited by a BEGIN and an END.
In our example, BLOCK t and BLOCK 2 contain just one statement each-
but shortly you will see longer blocks. A LOOP statement always means to
execute the block immediately under it repeatedly. As can be seen above,
blocks can be nested.
The strategy of the above algorithm is as described earlier. You begin
by taking an auxiliary variable, called CELL(O); you set it initially to 1, and
then, in a loop, you multiply it repeatedly by 3 until you've done so exactly
N times. Next, you do the analogous thing for CELL( t )-set it to 1, multiply
by 2 exactly CELL(O) times, then quit. Finally, you set OUTPUT to the value
of CELL( t). This is the value returned to the outside world-the only
externally visible behavior of the procedure.
A number of points about the notation should be made here. First, the
meaning of the left-arrow'¢:' is this:


Evaluate the expression to its right, then take the result and set the
CELL (or OUTPUT) on its left to that value.

So the meaning of a command such as CELL( t) ¢: 3 X CELL( t) is to triple
the value stored in CELL( t). You may think of each CELL as being a separate
word in the memory of some computer. The only difference between a
CELL and a true word is that the latter can only hold integers up to some
finite limit, whereas we allow a CELL to hold any natural number, no matter
how big.
Every procedure in BlooP, when called, yields a value-namely the
value of the variable called OUTPUT. At the beginning of execution of any
procedure, it is assumed as a default option that OUTPUT has the value O.
That way, even if the procedure never resets OUTPUT at all, OUTPUT has a
well-defined value at all times.


IF-Statements and Branching

Now let us look at another procedure which will show us som6 other
features of BlooP which give it more generality. How do you find out,
knowing only how to add, what the value of M - N is? The trick is to add
various numbers onto N until you find the one which yields M. However,
what happens if M is smaller than N? What if we are trying to take 5 from
2? In the domain of natural numbers, there is no answer. But we would like
our BlooP procedure to give an answer anyway-let's say O. Here, then, is a
BlooP procedure which does subtraction:

BlooP and FlooP and GlooP^411
Free download pdf