Lately I’ve been thinking about what to do to better understand compilers and interpreters, having done most everything so far by the seat of my pants. Fun, but not necessarily recommended. Some possibilities:
William Appel’s Modern Compiler Implementation in ML
I looked into the Nystrom’s book, and liked the first chapters, but the code, in Java, puts me off. I also looked into (3), but that would require learning ML. I tried this briefly, and it was pleasant. Most suited to my tastes was Stephen Diehl’s online book (2). There is, for example, this quote:
In mathematics a function is defined as a correspondence that assigns exactly one element of a set to each element in another set. If a function f(x)=a then the function evaluated at x will always have the value a. Central to the notion of all mathematics is the notion of equational reasoning, where if a=f(x) then for an expression g(f(x),f(x)), this is always equivalent to g(a,a). In other words, the values computed by functions can always be substituted freely at all occurrences.
The implementation may perform effects, but central to this definition is the unobservability of such effects. A function is said to be referentially transparent if replacing a function with its computed value output yields the same observable behavior.
The choice of (2) requires more Haskell than I am comfortable with, but my experience with Elm, another statically typed language of pure functions should help. I’m going to take the plunge!
I’ve had a pencil in my hand ever since I can remember. On the floor, under my grandmother’s table, scribbling away. On the SS United States returning from a year in Bad Kreutznach, Germany, where my father had been stationed during the Korean war. I can date the voyage precisely because one day, March 5, 1953, my mother, reading the ship’s paper at breakfast, announced that Stalin had died. I asked “who is Stalin.” A very bad man, she said. Paper on the ship was in short supply and we quickly ran out. My mother somehow managed to find a thick stack for us. A precious possession, it was rationed a few pages at a time. But this too soon ran out, after which the days became long indeed. The boredom was terrible, and we must have driven Mom crazy.
Much, much later, my own son started his drawing career, following much the same path that I and all other children follow. First random scribbles, carried out with great gusto and whole-arm motion, preferably in color, and not necessarily just on paper. Later circles of a sort appear, and soon one can find eyes, a mouth, ears, and hair — often wild, wild hair standing straight out or straight up. Arms and legs sprout from the circles, and there stand at last are human figures. Animals soon follow. About this time, I started making little picture books for my son, some with text, others pure imagery. All could be colored, and Dylan did that with enthusiasm, not necessarily respecting outlines. Why should one?
Giraffe in Picture Book for Dylan
Throughout my life I enjoyed making doodles and drawings. They also helped me think. About all sorts of things, but especially about mathematics and physics. There is a very visual element to much of these subjects. A gas is thought of as a container full of hard little balls zipping this way and that, bouncing off the walls and thereby creating what we experience as pressure. If we need more detail, we imagine arrows attached to the balls, short if they are moving slowly and long if they are moving fast. There is a fancy name, vector, for these arrows, and they can be described by a triple of numbers giving their velocities in the east-west, north-south, and up-down directions. Vectors even have their own little algebra. But what is fundamental, despite the power of the mathematics, is the mental picture of the balls zipping to and fro.
Scratch work for a computer project
Lately my interests have turned to applications of functional programming languages such as Elm to problems of parser and compiler construction. Such languages are made up entirely of pure functions. These are like the functions in mathematics: what is computed depends only on what information is given to the function as an input. Naturally, as a mathematician, this kind of language appeals to me. Again, as with mathematics or physics, visual thinking plays a role. On the right, for example is some scratchwork for a recent project — developing a configurable parser for a family of block-structured markup languages, if you want to know the buzzwords. Such work uses what are called parse trees, which look like what you see in the drawing. I had to figure out how manipulate these trees, detaching subtrees, changing them, and then reattaching them in just the right place. I tried pure thought, with eyes closed, but that didn’t work. Many sketches later, however, I had working code. It may very well be, and probably is, that other people working on the same problem don’t need to draw pictures. For me, it is essential.
I want to end with a comment. Though one can do a great deal with computer tools — word processors, graphics programs, etc — there is a difference both in the thought process and the physical experience when one uses pencil and paper. Thinking, for me at any rate, is much less constrained. (That is also why I prefer unlined paper. The lines are like a prison.) One can write diagonally, vertically, or in a curve, changing letter sizes from small to large and back again. One can doodle, and one can draw diagrams, even miniature works of art. There is also the physical experience of pressing the pencil against the paper, the ritual of sharpening the pencil, and even the smell of the pencil shavings. And one more thing. Consider a page of hand-written text, written in pencil or perhaps ball-point pen. Run your fingertips over it. Though you cannot read the text this way, you feel the letters. It is a thrill. It is a comfort.
As any of you know who have experienced fatherhood for long enough, there comes a time when the role of the father, so long a teacher of the child, begins change. Such is my case in many ways. Long ago it was “Papa, why does the moon follow us as we walk along the path?” Today it was “Dylan, could you help me set up this blog? I can’t figure it out.” But technical advice is the smallest part of it. As I write these pages, I find my words forming in a strange stylistic echo of the writing in Dylan’s blog, dilibop.wordpress.com. This all came about because of a lunchtime conversation a few days ago, when Dylan showed me his first posts. “Dad, you should do this too.” Things change.
The other day I happened on an episode of the Bulwark podcast in which political writer David Frum cites Hannah Arendt’s words on lies:
This is because lies, by their very nature, have to be changed, and a lying government has constantly to rewrite its own history. On the receiving end you get not only one lie—a lie which you could go on for the rest of your days—but you get a great number of lies, depending on how the political wind blows. And a people that no longer can believe anything cannot make up its mind. It is deprived not only of its capacity to act but also of its capacity to think and to judge. And with such a people you can then do what you please.
The source for Arendt’s words is a 1978 article in The New York Review of Books, based on a 1974 interview by the French writer Roger Errera. I give the date to underline the fact that a nearly 50-year-old description applies almost verbatim to today’s events. Frum’s mention of Arendt comes just after time code 00:04:02 in the podcast.