Abstract

@ as well as to the right) in order to give back the simple matrix result. In contrast, the SHARP APL approach doesn't require the Sharp equivalent of an enclosed array, and its subsequent disclosure, since it uses the generalization of scalar extension called cell extension, which is built-in to the rank operator.This was the state of things until early 1986. I was reasonably happy with what I had. Then I chanced to read (for reasons having nothing to do with the game of Life) Donald Knuth's book on his typefont designing system, Metafont [Kn86]. Among the data types in the METAFONT language is the picture. Looked at from the APL point of view, a METAFONT picture is a numeric matrix. The elements of a picture describe the way a plane surface is marked, that is, they describe a picture. Pictures can be added or subtracted, and can be shifted, reflected, and rotated by multiples of 90 degrees. In other words, METAFONT has stumbled through a back door into the same area where APL has held sway all alone for so many years. The book gives the following Exercise 13.24:In John Conway's “Game of Life,” pixels are said to be either alive or dead. Each pixel is in contact with eight neighbors. The live pixels in the (n+1)st generation are those who were dead and had exactly three live neighbors in the nth generation, or those who were alive and had exactly two or three live neighbors in the nth generation. Write a short METAFONT program that displays successive generations on your screen.Turning to the answers section of the book, I found Answer 13.24:13.24 (We assume that currentpicture initially has some configuration in which all pixel values are zero or one; one means “alive.”)picture v; def c = currentpicture enddef; forever: v := c; showit; addto c also c shifted left + c shifted right; addto c also c shifted up + c shifted down; addto c also c - v; cull c keeping (5, 7); endfor.(It is wise not to waste too much computer time watching this program.)I was impressed by this algorithm, because it reduced the number of vertical and horizontal rotations required from the eight that I had used in Nbr to three. Racing to my APL machine I translated Knuth's METAFONT algorithm into APL. I also began counting tokens at this point. The APL version of Knuth's algorithm used 49 tokens. ∇z ← LifeKnuth on n ← o o ← o + (1 p o) + - 1 p o o ← o + (1 t o) + - 1 t o o ← o + o - n z ← o ∈ 5 6 7 dThis APL algorithm isn't fully equivalent to Knuth's solution, since his METAFONT shifted primitive shifts in zeros, whereas the APL rotate primitive uses nondestructive cyclic rotation. By ensuring that the argument is bordered by an edge of zeros all around, the APL and METAFONT programs will be completely equivalent.The workings of this algorithm may not be immediately evident. What is happening was expressed as follows [Hu86]: in the pattern x x x x

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call