style and literacy in apl  … then the strut changed to the restless walk of a caged madman, then he whirled, and to a clash of cymbals in the orchestra and a cry of terror (perhaps faked) in the gallery, mascodagama turned over in the air and stood on his head. ---nabokov, ada "see me jump," said dick. "oh, my! this is fun. come and jump. come and do what i do." \---gray et al., the new fun with dick and jane  there is a persistent belief in the apl community, reflecting perhaps some of the prejudice against apl outside that community, that "good style" in apl involves writing very short statements, using as few primitives as possible in each. it is easy enough to find an example in a discussion of apl in a general computing magazine: mathematicians and engineers love apl for its conciseness and power, but there's quite a price to pay: apl programs are almost unreadable. it's very easy to write a single-line program that would take an average apl programmer a good fifteen minutes to figure out. … typically, good apl programmers write one line of comment for every line of code and try to keep their program lines short. [1]  such opinions don't spring forth full-grown from the forehead of zeus; they have their origins in the apl community (where else would an author, who does have his objective facts about apl straight, go for information about apl?).  for example, a recent issue of apl quote quad carried a "style guide" for functions submitted to the journal, including this: "vertical: write each function vertically with several short lines, rather than horizontally with long lines" [2]. another example: an otherwise admirable document on apl programming standards, circulated in the san francisco area, contains an appendix that introduces two functions by saying "the following are two functions which do the same thing. the first is a one liner which is pornographic. the second uses the same code but broken down into more readable pieces." [3] we will examine those two functions later in this paper.  first, let's explore this belief. short function lines seem to be a crucial point. that must mean, for example, that it should be considered better to write s +ω c pω z s÷c than z (+/ω)÷pω to calculate an average.  the justification is that the short statements are easier to read. this claim has gone unexamined for far too long. we will consider it from two perspectives:  in what way is a multiplicity of short statements easier to read than a single, longer one?  for whom is this style in general easier to read?  the first question is no doubt easy to answer. after all, if there's only one primitive (and assignment) in an expression, there can't be too much doubt about what that expression does, right? in c ω above, for instance, c is clearly the number of elements in ω whereas in a longer, more complicated expression, we might be daunted by the large number of funny squiggles, and never notice the p ω buried in there somewhere.  but does this really get us much farther in finding out what's going on? we're calculating an average, after all---there are two other statements involved. let's see: the first statement, s +/ω is just as easy: we're adding up the elements in \gw. oh, and giving them the name s. hope that's not too complicated, two things at once; pity we couldn't break it up further. only one to go. well, z s÷c is quite easy. nothing to it either. we're dividing s by c, of course. but, wait--- what was it we were doing? let's see, s was a sum, and c was, hold on a minute while we check, a count, that's right. so we're dividing the sum of things in ω by the number of things in ω\--- of course, this must be an average. there, we're done. easy, wasn't it?  go ahead, laugh. we know, you don't have trouble keeping three statements straight in your head. but when you're done laughing, think about the general claim in the light of this example. while breaking up a line into short segments does indeed produce a program whose lines are easier to read than the original, that isn't the appropriate unit of comparison: the lines in the fragmented version do nothing of interest. comparing the two programs is more interesting--- and here, the shoe is on the other foot. the fragmentation of thought, and the introduction of extra names into the calculation, makes it harder to keep track of what's going on, because to determine the meaning of the final result you must be aware of definitions that exist only in the immediate context, whereas in the brief and obvious (+/ω)÷pω everything is out where you can see it, and no reference is necessary to other parts of the expression. consider again the example paraphrased into english: instructions for computing an average (version 1) add up a bunch of numbers and divide by how many you had. instructions for computing an average (version 2) add up @@@@ bunch of numbers, and call the result "ess". count the numbers you added up, and call the result "cee". divide ess by cee.  but why stop here? english is an even richer language than apl; it can probably provide even, ah, clearer versions of the instructions: instructions for computing an average (version 3)  some instructions follow.  the instructions are about to begin.  you have a list of numbers.  reserve a spot called "ess" to put sums in.  put a zero in ess.  is there at least one number in the list?  if not, go to step 12.  name the first number in the list "ex".  add ex and ess, and call the result "ess" now.  remove the first number from the list.  go back to step 6.  …  we think we'll spare you (not to mention ourselves) the rest. actually we took some liberties there; that could be a lot clearer yet.  so. of versions 1, 2, and 3 of the instructions, which do you think needs comments most? maybe there are people who disagree, but our own feeling is that we'd definitely need to accompany 3 with some descriptive text (suppose we hadn't said what these instructions were meant to achieve?), probably some such text would also be handy for 2, and 1 needs it not at all. we assume none of our readers would actually prefer version 3, so let's leave it aside for now. but anyone who likes his apl expressions sold short (would you believe that as a typo and we meant "told"? no? oh well) presumably feels utterances such as version 2 of the instructions above are somehow more natural for human beings. we can only recommend experiment. we'd suggest the following one: next time you want a raise, be clear. don't tell your boss something confusing like "i want another thirty thousand dollars". say, "call my salary 'ess'. call thirty thousand dollars 'tee'. add ess and tee, and call the result 'ess'. thanks!" who knows, it may work better that way. but we doubt it would be because of greater clarity…  the intermediate names are only part of the story, though. version 3 of the instructions was not meant just to amuse us; it illustrates how easy it becomes to lose track of what's going on when a process is broken down into ridiculously tiny steps.  it also illustrates a more dangerous aspect of the "short and vertical" style of apl programming: carried just a little farther, it becomes scalar thinking--- conditioning a writer of apl to use this style risks encouraging inappropriate, inefficient use of the language as a tool.  the following function comes from an application in a real business environment:  what's wrong with this function? why, in one sense, nothing at all: it ran, it gave the proper answers, its author was happy with it for a long time. in another sense--- well, would you like to maintain it? or would you rather deal with something like the following:  there are, of course, a number of differences between the two, and some of them depend upon examination of the subfunction gpcalba (not shown here). one thing leaps immediately to one's notice: while there were a couple of fairly long lines in the first version, the second was certainly not produced by breaking them up! the two functions are equivalent; it took careful reading of gpcalba, a fairly involved function, to notice that there was no need at all for the nested loops and associated extra parameters in singleprems\\--- all the calculations were (or could be made) parallel for all cases, and all cases were always covered. had the consultant who did the work not been literate in apl, he could scarcely have made this simplification. perhaps more important--- the original form arose because scalar thinking is pervasive. people's approach to problems is conditioned by their habits. the first version of singleprems was written by an author not fluent in apl, who found it more congenial to address problems bit by bit. it reflects scalar thinking in its style: despite having middling long lines 2 and 6, most of the function conforms quite nicely to the "short and vertical" model. if you're conditioned to look at algorithms in tiny bits, chances are you'll look at problems the same way--- which means you'll lose much of the power of apl.  consider again, for a moment, the last two versions of the instructions for computing an average given above, with attention to style. what situation can you conceive, in which you would express yourself that way? version 3, in particular: you would never address another human being that way (well, save maybe your boss, if you did think that would get you a raise). you might address a machine that way. but, we hope, only when you didn't have any other choice. there are indeed many situations when you do have to address machines that way: when writing an apl interpreter, for instance. the tiny steps are in fact closer to how machines must execute our instructions, than to how human beings conceive of them. this is a partial answer to one of our questions: who finds instructions easier when they're broken up into very short bits? some machines do. apl doesn't require this because of its history: it was not originally defined to instruct machines. it is a human language.  but (tempting though it might be) we don't really feel it's fair to question the humanity of everyone who can't read the apl we write. fortunately, it isn't necessary. there are human beings we might want to address with very short sentences, made out of a very limited vocabulary: people who don't speak the language we're using very well. people whose language we don't speak very well. or, in writing: people of marginal literacy. people just learning to read.  implied in these categories is the answer to our other question: in what way are instructions easier to understand when they're broken up into tiny bits? they're easier to understand in that you can focus on the meanings of the words themselves--- which you might want to do when you're not very sure of them.  in all the cases in which people find it easier to understand broken english, it is generally expected that the problem is temporary. for some reason, in the case of apl, we have trouble even admitting that this is the problem. in apl, when the literacy problem is recognized, it's usually attacked by limiting--- often voluntarily--- the style of those who are literate to the comprehension level of those who are not. the problem is, indeed, partly one of writing. some people write english that's pretty hard to follow too. but at the level where it makes a critical difference to comprehension, to use only two or three words per sentence, the problem is simply learning to read.  this is also the case with apl. the major difference between apl and most other executable languages is simply that apl has a syntax sufficient to express thought; the others do not, and must use a sequence of steps instead. any accompanying thoughts had better be expressed in comments, in these other languages, even if they're simply thoughts descriptive of the process. in apl, the best description of the thought is in the apl itself, and as in english, the thought can be expressed most concisely, directly, and meaningfully when we're not restricting ourselves to an illiterate audience.  comments in english or some other natural language may still be desirable, but the useful ones are not descriptive, they're intentional: not what is this doing--- which the apl expresses better than english would--- but why is it doing it; or to what did the author expect to do it.  let's look at a different real example, one published to argue for the precise opposite of the position we take in this paper. the accompanying figure lists the two functions from [3] mentioned at the outset.  consider just the apl for the nonce, leaving aside the comments. we'll come back to those. spd may look a little forbidding at first--- if you're not used to reading apl, or if you think you should read it in the order a computer will execute it. but there's no need for reading in that direction: in the culture apl was developed, human beings are used to reading from left to right--- and that's a fine way of reading apl. as iverson remarks in a discussion of apl parsing rules, one important consequence of these rules is that in an unparenthesized sentence the right argument of any verb is the result of the entire phrase to the right of it. a sentence such as 3xp q*|r-5 can therefore be read from left to right; the overall result is three times the result of the remaining phrase, which is the maximum of p and the part following the , and so on. [4]  let's read our example, then, from left to right, as we're accustomed to. the first thing that leaps to our attention is a parenthesis; we don't know much about what it encloses yet, but we notice that immediately to its right is a p. we see immediately, then, that the result of spd is a reshape of some value (giving a matrix result). since what we're reshaping has just been transposed (reading on to the right), the parallel between the @@@@ arguments, and the left argument of the reshape, is very suggestive of collapsing two axes into one. this impression is reinforced by reading a little farther; the object transposed was itself the result of another reshape, and it in turn was the result of a on the right argument. a glance at the expression to the left of the , though it may not reveal exactly what the value is, shows clearly that we're dealing with an overtake, since d is assigned right there as the shape of x, and (reading the parenthesized phrase also from left to right) we see that the argument is more than that. so: that's the whole function. we've just skimmed it, but this skimming tells us most of the story: the result is a matrix containing all of the argument x, but rearranged in some way, and also some padding.  for many purposes, we could stop right there: a little experimentation would tell us the rest we might need to know. but we can read more carefully, too, and discover as much detail as we need.  look for a moment at the other version, spread. perhaps you can skim it as quickly as the first; we couldn't. there are rather more temporary variables involved to keep track of; the final reshape is not so suggestively associated with a transpose; the overtake is so buried and separated from its argument that, even knowing what it is and where it must be, we have trouble finding it.  but we didn't really finish reading the short spd; in particular, the expression c d+(col\col\- (d px)[1]), d seemed rather mysterious. notice, however, line [14] of the long spread\\--- it has exactly the same expression! slightly different variable names, and the x assignment has been moved, making it a little harder to see what one of the variables is… but no substantial difference. the rewrite, in other words, did absolutely nothing to clarify the one obscure part of this function. it is fairly clear that breaking this up further wouldn't do it. what does this do? well, there are two approaches--- one could try to simplify and analyze with no idea of where one was going; or one could take some knowledge of the intention of the function, together with reading of the rest of the function, to form a conjecture, which could then be verified. we took the second path; here's where comments come in handy--- we needed to know the author's intent. knowing the purpose of both functions (the comments on the first seem a little more helpful here), it was easy to conjecture that the overtake must be to pad the original data x to a number of rows which is an even multiple of the number of "logical columns" desired, col\\--- therefore, our conjecture was that this phrase must be equivalent to c (colx (1 d),÷col), 1 d x a short proof verified that this was indeed the case. note that the "skimming" we went through in the first place was crucial to form the conjecture (which made the analysis, we suspect, much shorter than if we'd had no idea where we were going). this skimming, as we began by showing, is much easier when all the context is immediately in front of us. that is, for the one part of both functions that is hard to understand, spd\\--- the "nasty" one- liner--- makes it easier to discover the meaning than the broken-up spread.  our central conclusion was arrived at before examining this example: that the problem of written communications, in apl as in english, requires skills on the part of the reader as well as on the part of the writer. the responsibility for communication has been laid too heavily on writers in the apl community.  modifying one's apl writing style to cater to an illiterate audience has been a recommended approach. we have tried to show, first, that becoming accustomed to a less expressive style of writing can hamper a writer's thinking in approaching a problem; second, that reading skills are valuable in themselves; and, finally, that --- assuming readers of apl are willing and able to read --- the often-recommended "short and vertical" style makes it harder, rather than easier, to read apl, especially when obscure phrases are encountered in either style.  as with any aesthetic issue, the question of good style in apl cannot be settled prescriptively. a final, and perhaps the weightiest, reason for developing apl reading skills is that to read is, in the final analysis, the most sensible advice one can give to writers concerned with improving their own style. iverson has remarked that perhaps the most important habit in the development of good style in a language remains to be mentioned, the habit of critical reading. such reading should not be limited to collections of well- turned and useful phrases…nor should it be limited to topics in a reader's particular specialty.…one may benefit from the critical reading of mediocre writing as well as good; good writing may present new turns of phrase, but mediocre writing may spur the reader to improve upon it. [5]  perlis and rugaber [6] have advocated teaching the recognition of particular phrases (often called "idioms" in the apl community) as a useful step in teaching both reading, and writing, of apl. published collections of such phrases include perlis and rugaber's report the apl idiom list [7] and the more recent finnapl idiom library [8]. as iverson remarks, such collections are certainly one kind of useful reading matter. but by themselves they are unlikely to make anyone literate, and in fact careless use of such collections in teaching can sometimes disguise illiteracy rather than promote literacy, if students feel encouraged to simply accept, recognize, and copy such phrases rather than actually reading and analyzing them (see pesch [9] for more discussion of this issue).  we can provide no easy answers: but this much is clear--- writers of apl must assume a literate audience (as writers of english do) if they are to use the language effectively; and readers of apl (which is to say all of us) can read best by reading more. in the end, greater literacy is its own reward.  michael j. berry roland h. pesch