<< . .

. 26
( : 45)

. . >>

| picture tertiary plus or minus picture secondary string expression
picture expression ’’ picture tertiary &

Chapter 13 is the de¬nitive reference for picture operations.
Strings are still fresh in our minds from Chapter 22, but we should repeat the
syntax again for completeness here.
string primary ’’ string variable | string argument
| string token
| jobname
| readstring
| ( string expression )
| begingroup statement list string expression endgroup
| str su¬x
| char numeric primary
| decimal numeric primary
| substring pair primary of string primary
string secondary ’’ string primary
string tertiary ’’ string secondary
string expression ’’ string tertiary
| string expression & string tertiary
There™s nothing more to say about strings.
Chapter 25: Summary of Expressions 215

Chapter 15 explains transforms, but gives no formal syntax. The rules are: transform primary
transform primary ’’ transform variable | transform argument )
| ( transform expression ) endgroup
| begingroup statement list transform expression endgroup transform secondary
transform secondary ’’ transform primary transform tertiary
transform expression
| transform secondary transformer identity
transform tertiary ’’ transform secondary vacuous primary
transform expression ’’ transform tertiary (
Note that identity doesn™t appear here; it is a variable de¬ned in Appendix B, not a endgroup
primitive of the language. vacuous secondary
vacuous tertiary
Finally, we come to the new kind of expression, which wasn™t mentioned in vacuous expression
previous chapters because it is so trivial.
vacuous primary ’’ vacuous argument
| compound
| ( vacuous expression )
| begingroup statement list vacuous expression endgroup
vacuous secondary ’’ vacuous primary
vacuous tertiary ’’ vacuous secondary
vacuous expression ’’ vacuous tertiary
A compound is de¬ned in Chapter 26.
Construct minimal examples of each of the nine types of expression (boolean,
numeric, . . . , vacuous). You should use only “sparks” in your constructions, not tag
tokens or capsules; in particular, variables are not permitted (otherwise this exercise
would be too easy). Your expressions should be as short as possible in the sense of
fewest tokens; the number of keystrokes needed to type them is irrelevant.

This is of you very well remembred,
and well and sommaryly rehersed.
” THOMAS MORE, A Dialogue Concernynge Heresyes (1529)

Below the tomato blobs was a band of white with vertical black stripes,
to which he could assign no meaning whatever,
till some one else came by, murmuring:
“What expression he gets with his foreground!”
. . . Ah, they were all Expressionists now, he had heard, on the Continent.
So it was coming here too, was it?
” JOHN GALSWORTHY, To Let (1921)
(page 216)

Summary of
the Language
Chapter 26: Summary of the Language 217

The grand tour of ™s syntax that was begun in the previous chapter truth
anatomy of METAFONT
is concluded in this one, so that a complete reference guide is available for people program
who need to know the details. (Another summary appears in Appendix B.) end
statement list
actually has a few features that didn™t seem to be worth men-
tioning in earlier chapters, so they will be introduced here as part of our exhaustive statement
survey. If there is any disagreement between something that was said previously and title
something that will be said below, the facts in the present chapter should be regarded
as better approximations to the truth. endgroup
We shall study ™s digestive processes, i.e., what does command
in response to the tokens that arrive in its “stomach.” Chapter 6 describes the process
by which input ¬les are converted to lists of tokens in ™s “mouth,” and
Chapters 18“20 explain how expandable tokens are converted to unexpandable ones in
™s “gullet” by a process similar to regurgitation. In particular, conditions
and loops are handled by the expansion mechanism, and we need not discuss them
further. When unexpandable tokens ¬nally reach ™s gastro-intestinal tract,
the real activities begin; expressions are evaluated, equations are solved, variables are
declared, and commands are executed. In this chapter we shall discuss the primitive
operations that actually draw pictures and produce output.
Let™s start by looking at the full syntax for program and for statement :
program ’’ statement list end | statement list dump
statement list ’’ empty | statement ; statement list
statement ’’ empty | title
| equation | assignment
| declaration | de¬nition
| compound | command
title ’’ string expression
compound ’’ begingroup statement list non-title statement endgroup
command ’’ save command
| interim command
| newinternal command
| randomseed command
| let command
| delimiters command
| protection command
| everyjob command
| show command
| message command
| mode command
| picture command
| display command
| openwindow command
| shipout command
| special command
| font metric command
The empty statement does nothing, but it is very handy because you can always feel
safe when you put extra semicolons between statements. A title does almost noth-
218 Chapter 26: Summary of the Language

ing, but it provides useful documentation as explained in Chapter 22. The syntax of commands
save command
equation and assignment can be found in Chapter 10; declaration is in Chapter 7;
de¬nition is in Chapters 18 and 20. We shall concentrate in this chapter on the symbolic token list
various types of commands, especially on those that haven™t been mentioned before. ,
interim command
save command ’’ save symbolic token list interim
symbolic token list ’’ symbolic token newinternal command
| symbolic token list , symbolic token newinternal
interim command ’’ interim internal quantity := right-hand side external tags
randomseed command
The save and interim commands cause values to be restored at the end of the current randomseed
group, as discussed in Chapter 17. :=
newinternal command ’’ newinternal symbolic token list time
let command
Each of the symbolic tokens speci¬ed in a newinternal command will henceforth
behave exactly as an internal quantity , initially zero. Thus, they can be used in =
interim commands; they are tags but not external tags (see Chapter 7). Since - :=
delimiters command
can access internal quantities quickly, you can use them to gain e¬ciency. delimiters
protection command
randomseed command ’’ randomseed := numeric expression outer
The randomseed command speci¬es a “seed” value that de¬nes the pseudo-random forbidden
numbers to be delivered by ˜uniformdeviate™ and ˜normaldeviate™ (cf. Chapter 21). The
default value, if you don™t specify your own seed, is day + time — epsilon .
let command ’’ let symbolic token is symbolic token
is ’’ = | :=
The let command changes the current meaning of the left-hand token to the current
meaning of the right-hand token. For example, after ˜let diamonds = forever™, the
token diamonds will introduce loops. If the left-hand token was the ¬rst token of
any variable names, those variables all disappear. If the right-hand token was the ¬rst
token in any variable names, those variables remain unchanged, and the left-hand token
becomes an unknown, independent variable. (The purpose of let is to rede¬ne primitive
meanings or macro meanings, not to equate variables in any way.) If the right-hand
symbol is one of a pair of matching delimiters, the subsequent behavior of the left-hand
symbol is unde¬ned. For example, it™s a bad idea to say ˜let [ [= (; let ] ] =)™.
delimiters command ’’ delimiters symbolic token symbolic token
The delimiters command gives new meanings to the two symbolic tokens; henceforth
they will match each other (and only each other). For example, Appendix B says
˜delimiters ()™; without this command, parentheses would be ordinary symbolic tokens.
Any distinct symbolic tokens can be de¬ned to act as delimiters, and many di¬erent
pairs of delimiters can be in use simultaneously.
protection command ’’ outer symbolic token list
| inner symbolic token list
A “forbidden” stamp is added to or removed from symbolic tokens by an outer or inner
command, without changing the essential meanings of those tokens. A token that has
been called outer should not appear when is skipping over tokens at high
Chapter 26: Summary of the Language 219

speed; the program will stop and insert an appropriate delimiter, if an outer token condition
replacement text
is sensed in the wrong place, since such tokens are supposed to occur only at “quiet”
loop text
times. (Unquiet times occur when is skipping tokens because of a false text argument
condition, or because it is reading the replacement text of a macro or the loop text of ¬‚ushing
everyjob command
a loop, or because it is scanning the text argument to a macro, or because it is ¬‚ushing everyjob
erroneous tokens that were found at the end of a statement.) Without such protection, show command
a missing right delimiter could cause to eat up your whole program before
any error was detected; outer tokens keep such errors localized. An inner command showtoken
undoes the e¬ect of outer; so does ˜let™, and so does any other command or de¬nition showdependencies
that changes the meaning of a symbolic token. All tokens are initially inner.
everyjob command ’’ everyjob symbolic token OK.
The command ˜everyjob S™ tells that token S should be inserted ¬rst, message command
just before the input ¬le is read, when a job starts. (This is meaningful only in a base message op
¬le that will be loaded or preloaded at the beginning of a run; it is analogous to TEX™s
\everyjob command.) errhelp
mode command
show command ’’ show expression list batchmode
| showvariable symbolic token list nonstopmode
| showtoken symbolic token list errorstopmode
| showdependencies interrupting
| showstats
A simple show command displays the value of each expression, in turn. Paths, pens,
and pictures are shown only in the transcript ¬le, unless tracingonline is positive.
The showvariable command gives the structure of all variables that begin with a
given external tag, together with their values in an abbreviated form; this allows you
to see which of its subscripts and attributes have occurred. For example, if you™re
using plain conventions, ˜showvariable x, y™ will show all coordinates
that have been de¬ned since the last beginchar. The showtoken command gives
the current meaning of a token, so that you can tell whether it is primitive or not,
outer or not. (If showvariable is applied to a spark instead of a tag, it gives the
same information as showtoken.) Every unknown numeric variable that™s currently
dependent is shown by showdependencies (except that unknown capsules are shown
only when tracingcapsules is positive). And ¬nally, showstats gives information about
™s current memory usage. Each of these commands will stop and say ˜! OK.™,
if the internal quantity showstopping has a positive value; this gives you a chance to
enter more show commands interactively, while you™re trying to debug a program.
message command ’’ message op string expression
message op ’’ message | errmessage | errhelp
Communication with the user is possible via message, errmessage, and errhelp, as
discussed in Chapter 22.
mode command ’’ batchmode | nonstopmode
| scrollmode | errorstopmode
The four “mode commands” control the amount of interaction during error recovery,
just as in TEX. A job starts in errorstopmode, and you can also resurrect this mode
by interrupting ; scrollmode, nonstopmode, and batchmode are the
220 Chapter 26: Summary of the Language

modes you get into by hitting ˜S™, ˜R™, or ˜Q™, respectively, in response to error messages picture command
addto command
(cf. Chapter 5).
picture command ’’ addto command | cull command addto
addto command ’’ addto picture variable also picture expression contour
| addto picture variable contour path expression with list addto
| addto picture variable doublepath path expression with list with list
with list ’’ empty | with list with clause with clause
with clause ’’ withpen pen expression | withweight numeric expression withpen
cull command ’’ cull picture variable keep or drop pair expression cull command
| cull command withweight numeric expression cull
keep or drop ’’ keeping | dropping keep or drop
The addto and cull commands are the principal means of making changes to pictures; dropping
they are discussed fully in Chapter 13. display command
display command ’’ display picture variable inwindow window inwindow
window ’’ numeric expression openwindow command
openwindow command ’’ openwindow window window spec openwindow
window spec ’’ screen place at pair expression window spec
screen place ’’ from screen coordinates to screen coordinates screen place
screen coordinates ’’ pair expression from
screen coordinates
Chapter 23 explains how to display stu¬ on your screen via display and openwindow.
shipout command
shipout command ’’ shipout picture expression shipout
generic font
You may have wondered how actually gets pictorial information into a xo¬set
font. Here at last is the answer: ˜shipout v™ puts the pixels of positive weight, as yo¬set
de¬ned by the picture expression v, into a generic font output ¬le, where they will be
the bitmap image associated with character number charcode mod 256 + charext — 256. charwd
The pixels of v are shifted by (xo¬set , yo¬set ) as they are shipped out. (However, no charht
output is done if proo¬ng < 0. The values of xo¬set , yo¬set , charcode , and charext are charic
¬rst rounded to integers, if necessary.) This command also saves the values of charwd , chardx
font metric information
charht , chardp , charic , chardx , and chardy ; they will be associated with the current
special command
charcode when font metric information is produced. (See Appendices F and G for the special
basic principles of font metric information and generic font ¬les.) numspecial

special command ’’ special string expression
| numspecial numeric expression
The special and numspecial commands send alphabetic and numeric information
to the generic font output ¬le, if proo¬ng is nonnegative. For example, the labels on
proofsheets are speci¬ed in this way by macros of plain . Appendices G
and H provide further details.
We have now discussed every kind of command but one; and the remaining one
is even more special than the special command , so we had better defer its discussion to
an appendix. Appendix F will complete the syntax by de¬ning font metric command .
For now, we merely need to know that font metric commands specify fussy font facts;
examples are the kerning and ˜font normal space™ statements in the logo
program of Chapter 11.
Chapter 26: Summary of the Language 221

And there™s one more loose end to tie up, going back to the very ¬rst syntax dump
rule in this chapter: The token ˜dump™ can be substituted for ˜end™, if a special version
of called ˜INIMF™ is being used. This writes a ¬le containing the macros outer
de¬ned so far, together with the current values of variables and the current meanings delimiters
of symbolic tokens, so that they can be loaded as a base ¬le. (It is analogous to TEX™s THOREAU
\dump command.) Base ¬les are discussed at the end of Appendix B. truth
Run with the input
\newinternal a;
let b=a; outer a,b,c;
let c=b; delimiters a::;
showtoken a,b,c; end
and explain the computer™s responses.

Our life is frittered away by detail.
An honest man has hardly need
to count more than his ten ¬ngers,
or in extreme cases he may add his ten toes,
and lump the rest. Simplicity, simplicity, simplicity!
I say, let your a¬airs be as two or three,
and not a hundred or a thousand . . .
Simplify, simplify.
” HENRY DAVID THOREAU, Walden (1854)

The awesome memory of thy ever attentive computer
accepts all words as truth.
Think, therefore, in analytical, modular steps,
for the truth or untruth spoken through thy ¬ngertips
will be acted upon unerringly.
” HERMANN ZAPF, The Ten Commandments of Photo -Typesetting (1982)
(page 222)

Chapter 27: Recovery from Errors 223

OK, everything you need to know about has been explained”unless error messages
you happen to be fallible. If you don™t plan to make any errors, don™t bother to !
read this chapter. Otherwise you might ¬nd it helpful to make use of some of to be read again
isolated expression
the ways that tries to pinpoint bugs in your programs. semicolon
In the trial runs you did when reading Chapter 5, you learned the general statement
form of error messages, and you also learned the various ways in which you can
respond to ™s complaints. With practice, you will be able to correct
most errors “online,” as soon as has detected them, by inserting
and deleting a few things. On the other hand, some errors are more devastating
than others; one error might cause some other perfectly valid construction to be
loused up. Furthermore, doesn™t always diagnose your errors cor-
rectly, since the number of ways to misunderstand the rules is vast;
is a rather simple-minded computer program that doesn™t readily comprehend
the human point of view. In fact, there will be times when you and
disagree about something that you feel makes perfectly good sense. This chapter
tries to help avoid a breakdown in communication by explaining how to learn
™s reasons for its actions.
Ideally you™ll be in a mellow mood when you approach , and
you will regard any error messages as amusing puzzles”“Why did the machine
do that?””rather than as personal insults. knows how to issue more
than a hundred di¬erent sorts of error messages, and you probably never will
encounter all of them, because some types of mistakes are very hard to make.
Let™s go back to the ˜badio.mf™ example ¬le of Chapter 5, since it has
more to teach us. If you have a better memory than the author, you™ll recall
that the ¬rst error message was
>> mode.setup
! Isolated expression.
<to be read again>
l.1 mode setup;
% an intentional error!

In Chapter 5 we just charged ahead at this point, but it would be more normal
for a mature er to think “Shucks, I meant to type ˜mode_setup™, but

<< . .

. 26
( : 45)

. . >>