## How iteration is doneThe mechanism used to perform iteration described in
the two papers on Full Metal Jacket is now
obsolete, though it will make a limited comeback when we examine macros.
Iteration is now performed in Full Metal Jacket by means of feedback.
This, however, poses a problem: how do we get feedback
in an The answer is that while the visible graphs are acyclic, the underlying graphs through which the data really flow are cyclic whenever iteration is used. Iteration uses two special linked vertices called
So ## Counting
zeroth iteration:
first iteration:
... tenth iteration:
## Reading a file and printing its contentsSimilary, we can print the contents of a file. Files should really be obsolete: a modern operating system should have different types of objects and the ability to address them as if they were in main memory. Better still, there shouldn't be an operating system. Programming languages should run on the bare metal. But, for now, we're stuck with Unix.
## Newton's methodNext, we compose a function containing feedback, which implements Newton's method for calculating the square root of a number. This is done by first approximating the square root, and then repeatedly calculating better values until the differences are small: repeat a' ← (x / a + a) / 2 until |a' - a| < 0.000001; return a' where The first input is the number we want the square root of,
and the second is our initial approximation. We hard-coded the accuracy
as First, √10.0 is calculated using the built-in function. Our implementation of Newton's method is correct to the accuracy chosen, even with 1.0 as the first approximation. ## Balancing inputsIt is important that the same number of values arrive at each input of a vertex in any computation. If they do not, a queue will build up, containing the excess values. During a call, - One value is transmitted from each ingate.
- One value is received on each outgate.
- If N values are received on each input of
`when+` and`unless+` , and A values are sent from each output of`when+` , then N-A values will be sent from each output of`unless+` . - One value is received on each input of
`start+` , N values are sent from each output, and N-1 values are received on each input of`repeat+` . (NB This is only what appears to happen. When executing, values are really sent directly to`start+` , bypassing`repeat+` .) - All other vertices receive N values on each of their inputs, and send N values from their outputs.
The above rules can be applied statically, to verify that the same number of inputs is received on each input of a vertex. If this does not happen, it indicates a bug, even when the function being checked returns correct values. © Copyright Donald Fisk 2015, 2016 |