Tugboat, Volume 35 (2014), No. 1 99 Macro Memories, 1964–2013 David
Total Page:16
File Type:pdf, Size:1020Kb
TUGboat, Volume 35 (2014), No. 1 99 Macro memories, 1964{2013 I assume most readers know what macros are, but just in case: Typically one gives a name to a string David Walden of text, e.g., \\define\Macroname{Textstring}"; Contents then each time \\Macroname" is found (\called") in the input text stream, it is replaced by \Textstring". 1 McIlroy's 1960 ACM paper 99 The macro definition can involve the additional 2 Some prior history of macros 100 substitution of text specified when the macro defini- 3 Strachey's General Purpose Macrogenerator 101 tion is called. For example, 4 Midas macro processor 101 \define\Name#1{His name is #1} 5 More study and use of macro processors defines a macro named \Name" where \#1" indicates (and language extension capabilities) 102 a parameter to be substituted for when the macro is 6 Midas, macros, and the called. The macro might be called with \John" as ARPANET IMP program 103 the substitution text, as in the following 7 Ratfor and Infomail 104 \Name{John} 8 TEX, macros for typesetting 104 which would result in 9 M4 106 His name is John 10 Reflections 107 In addition to the \#1" indicating where a substitu- Introduction tion is to take place in the macro definition when In the summer of 2013, I was looking at a 1973 listing the macro is called, in this example the \#1" imme- of the ARPANET IMP (Interface Message Processor) diately after the macro name indicates there is one program1 which makes extensive use of macros. This such substitutable parameter. If there were more caused me to muse about the various macro proces- than one such parameter, a list such as \#1#2#3" sors I have used over the past 50 years which, in turn, would appear after the macro name in the definition, led to this note. specifying three such parameters. This note is not a thorough study, extensive Donald Knuth in the index to Volume 1 of The Art of tutorial, or comprehensive bibliography about macro Computer Programming gives this succinct definition processors. Such descriptions have already been pro- relating to macros: \Macro instruction: Specification vided by, for instance, Peter Brown, Martin Campbell- of a pattern of instructions and/or pseudo-operators Kelly, John Metzner, and Peter Wegner in their that may be used repeatedly within a program." longer presentations of the topic.2,3,4,5 Instead, the 1 McIlroy's 1960 ACM paper macro technology thread I follow herein is guided by the order in which I used or studied the various macro I'm pretty sure that while I was still in college at San processors. I hope this is usefully representative of Francisco State (1962{64) and using an IBM 1620 the scope of macro processor technology. computer, I had no concept of macros. The IBM I have three reasons for writing this note. (1) I 7094 at MIT Lincoln Laboratory, my first employer haven't seen much new written about macro pro- after college (starting in June 1964), may have had cessors in recent years (other than what is on the a macro assembly capability, but I don't think I ever web); thus, it is perhaps time for a new paper on used it. this sometimes under-appreciated topic. (2) Com- Probably my first contact with the concept of puter professionals and computing historians who macros was when an older colleague at Lincoln Lab have come to their fields only in the last decade or gave me his back issues of the Communications of two may not know much about macros, and this the ACM (and I joined the ACM myself to get future is a chance to share my fondness for and perspec- issues of the CACM). In one of these back issues, tive on macros. The citations in the endnotes also I read the article by Doug McIlroy on macros for may be a useful starting point for further study of compiler languages.6 macros, and maybe these notes will rekindle mem- McIlroy has the following example of defining a ories for other long-time computing people like me macro (although I am using an equal sign where he about some of their own experiences. (3) For (LA)TEX used an identity symbol): users who may not be computer programmers or fa- ADD, A, B, C = FETCH, A miliar with other macro processor systems and who ADD, B accomplish impressive things using TEX macros, this STORE, C note sketches the long technical history of which TEX where ADD7 is the macro name, and A, B, and C are macros are a part. the names of macro arguments to be filled in at the Macro memories, 1964{2013 100 TUGboat, Volume 35 (2014), No. 1 time of the macro call, and the three lines of code Apparently Bell Labs was a particular hotbed are what is substituted. Thus, McIlroy shows this of macro activity in those early days. In a memorial macro being called with the sequence note for Douglas Eastwood,8 Doug McIlroy recounts: ADD, X, Y, Z On joining the Bell Labs math department, I resulting in the following: was given an office next to Doug Eastwood's. Soon after, George Mealy . suggested to a FETCH, X ADD, Y small group of us that a macro-instruction STORE, Z facility be added to our assembler . This idea caught the fancy of us two Dougs, and This style of macro definition uses symbolic names set the course of our research for some time for the substitutable parameters, which can be useful to come. We split the job in half: Eastwood in remembering what one is doing with long macro took care of defining macros; McIlroy handled definitions. However, it is also a bit more complicated the expansion of macro calls. to implement such symbolic macro parameter names The macro system we built enabled truly compared with using special codes such as \#1". astonishing applications. Macros took hold McIlroy's 1960 paper goes on to show examples in the Labs' most important project, elec- of macros in an ALGOL-like language and to explain tronic switching systems, in an elaborated the benefits of various features of macro processors. form that served as their primary program- For instance, ming language for a couple of decades. macro exchange(x,y;z) := Once macros had been incorporated, the begin assembler was processing code written whole- begin integer x,y,z; sale by machine (i.e., by the assembler itself) z:=y; y:=x; rather than retail by people. This stressed the x:=z; assembler in ways that had never been seen be- end exchange x and y fore. The size of its vocabulary jumped from end exchange about 100 different instructions to that plus defines a macro which, if called with an unlimited number of newly defined ones. The real size of programs jumped because one exchange(r1,ss3) human-written line of code was often short- results in hand for many, many machine-written lines. begin integer r1,ss3,.gen001 And the number of symbolic names in a pro- .gen001:=r1; gram jumped, because macros could invent ss3:=r1; new names like crazy. r1:=.gen001; By the way, Rosen's book7 also had a paper (pp. 535{ end exchange r1 and ss3 559) by George Mealy that touched on macros: \A Note that a special temporary register, .gen001, was Generalized Assembly System (Excerpts)". created to replace z which was defined following the semicolon in the parameter list. 2 Some prior history of macros McIlroy's paper also has a summary list of \sa- McIlroy's paper also hints at some of the history of lient features" [the comments below in square brack- macro processors including half a dozen references9 ets are my notes on McIlroy's list]: to prior macro processors; they were becoming fairly 1. definitions may contain macro calls widespread by the early 1960s. Lots of people were 2. parenthetical notation for compounding calls thinking about macros and macro processing by 1960. [e.g., so arguments to macro calls can include In section 6 of his paper, McIlroy says, multiple items separated by commas] . Conditional macros were devised indepen- 3. conditional assembly dently by several persons beside the author in the past year. In particular, A. Perlis pointed 4. created symbols [e.g., so labels or local variable out that algorithms for algebraic translation names in the body of a macro definition are could be expressed in terms of conditional unique for each call of the macro] macros. Some uses of nested definitions were 5. definitions may contain definition schemata discovered by the author; their first imple- 6. repetition over a list [see the example in the mentation was by J. Benett also of Bell Tele- discussion of Midas in section 4] phone Laboratories. Repetition over a list is David Walden TUGboat, Volume 35 (2014), No. 1 101 due to V. Vyssotsky. Perlis also noted that possible preprocessor for any other language or as a macro compiling may be done by routines to a stand-alone string processor. large degree independent of ground language. Here is a simple definition in GPM: One existing macro compiler, MICA (Haigh), §DEF,REFORMATNAME,<LAST=~2, FIRST=~1>; though working in only one ground language is It could be called like this: physically separated from its ground-language compiler. An analyzer of variable-style source §REFORMATNAME,David,Walden; languages exists in the SHADOW routine of which would produce the output: M. Barnett, but lacks an associated mecha- LAST=Walden, FIRST=David nism for incorporating extensions.