APLpip
Vector 1:2, page 109
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 109
I was very interested in the matter of an ASCII-based character set for APL which was the subject of Mr Bowman’s letter as well as being a topic of numerous articles elsewhere in VECTOR Vol.1 No.1. I became so moved by the force of the arguments in its favour that I felt impelled to sit down and try to design one which would lose less in brevity than FGL, because brevity is not only the soul of wit, it is also one of APL’s greath strengths.
Now APL has a set of about 140 characters whereas ASCII, a 7-bit code, has only 128 made up of:— 32 characters used for controlling communication and printing; space; DEL; and 94 graphics. If you set aside two of these for use as set selectors (like FIGURE shift and LETTER shift in BAUDOT code) you can have two sets of 94 codes which together are large enough to encompass APL’s 140. However, I was less concerned about this than with trying to squeeze a workable APL scheme into a single sheet. This task that I set myself was successfully completed, and now — with the benefit of hindsight — performing it seems to have been fairly straightforward. Here’s how it went.
Trying to fit 140 characters into a set of 94 is like trying to put a quart into a pint pot — you can’t do it without spilling some. The characters I thought were eminently spillable are those which are not presently in common use, and along with them went the UNDERBAR, UNDERBAR DELTA, and the UNDERSCORED ALPHABETICS — relics from the days of backspacing and overstriking — nice to keep as souvenirs, but not essential, and therefore a luxury that I just couldn’t afford. This brought the number of characters required for a one-to-one mapping down by 35, but it still wasn’t enough.
I was aware of two commonly known multi-character substitutes for SLOPE BAR and SLASH BAR, so I knew I could save another two codes by using those instead. Further savings, I thought, could come from substituting compounds such as NOT AND and NOT OR for NAND, NOR etc, but then I remembered that NOT can only be used monadically whereas NAND and NOR can also be used dyadically, so I had to think again. I finally settled on three compounds culled from BASIC to substitute for NOT GREATER etc, and I made up three others which I find aesthetically pleasing as replacements for NAND etc. Unlike the first two, the last six would cause SYNTAX ERROR in conventional APL, but in a purpose-built interpreter they would be tokenised and stored internally as single codes which would function in precisely the same way as the APL symbols which they represent. So, by eliminating 43 APL symbols in all, I had just enough ASCII codes to do the job, and the task of mapping one set to another could begin.
With APL and ASCII sharing a common subset of 56 characters I was off to a flying start and more than half way there. I then looked at the remaining ASCII symbols and was greatly surprised by the ease with which each seemed to find its APL counterpart. It was almost as if someone up above was smiling on me! Eleven of them are imitative, one is symbolically synonymous, and DOLLAR, which looks nothing like DEL(ta) does at least have a name which sounds similar. It also carries with it an air of authority which makes it very suitable for the important role of function definition. I very much prefer this restrained usage of the symbol to the profligate way it is used in BASIC to make program listings look cluttered and data names unpronounceable. And now, with 69 character assignments made, I was nearly three-quarters of the way there, and had only to find 25 equivalences from the lower-case alphabet which held all the remaining ASCII characters.
The characteristic which I most prized in carrying out this task was mimicry. Nine of the lower-case alphabetics possess this attribute, in degrees ranging from excellent to fairly good. Four of them are also mnemonic in the sense that they prefix common names for the APL symbols they represent, another valuable attribute, and the only one available for deciding the rest of the assignments. Six more were matched on this basis alone, but for the last ten the best I could do was to look for words or phrases which began with the available letters and which were synonymous with the action or purpose of the APL symbols to which they would be assigned. You might not like the words that I came up with, but they will all be remembered by their initial letter mnemonics. The unassigned letter is k. Together with the ASCII DEL it provides a pair of set selectors which will enable a second set to be defined later on. Finally, there remained only two more things to do: what to call this creation; and what to do with it.
I chose the name APLpip because it encapsulates my hopes for its future — a vision of growth and proliferation for my favourite programming language. I am donating the copyright to the British APL Association because I think it will be the best body to promote and regulate its usage.
Here are some of the things it can provide:—
- A means of representing APL code in print.
- A means of transmitting and listing APL workspaces of all sorts under ASCII protocol.
- A basis for alternative interpreters enabling:—
- (a) APL software to run on unmodified ASCII hardware and yet be maintainable ‘in situ’.
- (b) APL to be learned and used on very low cost hardware by the school and hobbyist communities.
I will discuss each one briefly.
APLpip for publishing¶
APLpip can be used to overcome the typesetting problem referred to by the Editor on page 5 of VECTOR Vol.1 No.1
The atomic vector of VS APL — and many others, as well, I suspect — contains most of the ASCII symbols as well as all those of APL. It is easy in APL to write a function whose argument is the name of any function in the workspace and get it to convert the function’s canonical representation to APLpip format. Thus contributors can create copy for typesetting without any risk of mistranslation. Similarly, recipients can enter the APLpip format and use a complementary function together with quad-FX to create a ready-to-run orthodox APL program.
Adoption of this procedure would not only overcome the typesetting problem, but also make available to schools and hobbyists using APLpip interpreters high quality software which would otherwise have to be translated before being entered.
Function listings look hardly any different from normal APL code because 95% of the graphics used to represent the functions are either part of the APL set or ASCII lookalikes.
ASCII protocol¶
The availability of a pair of set selectors permits one more set of 94 characters to be used to accommodate the 43 APL codes excluded from the first whilst still leaving plenty of spare room for expansion. This means that APL workspaces of all sorts could be transmitted and printed under ASCII protocol. Second set characters are so infrequently used that the overhead in characters to switch from one set to another would not be very significant. A printing convention of underlining characters of the second set would enable them to be visually distinguished from those of the first.
APLpip Interpreter Advantages¶
APL software is often run at non-APL terminals, but the lack of APL symbols on their keyboards can sometimes leave programmers helpless. A STACK FULL condition can prevent them from doing anything but using system commands or calculator mode, for a CLRSTACK function is rendered inoperable when its name cannot be pushed onto the stack. APLpip would enable them to overcome this problem by simply entering “g” and then CLRSTACK. It could also enable any software maintenance to be carried out ‘in situ’.
Because demand is elastic and competition has been fierce the schools and hobbyist sectors of computing have become huge. Prices are keen, buyers fastidious, and accustomed to getting enormous value for money. And yet, with a few notable exceptions, APL has made no impact on these markets whatsoever. Robert Bittlestone has said, and he should know, (Ed. — should he?) that one cause of this is the inordinately high cost of using APL symbols. So if you remove this obstacle, APL should flourish, shouldn’t it?
Three of the Association’s sustaining members have great experience of developing and marketing APL interpreters written for Z80 machines, but because of the move towards more powerful 16-bit processors their Z80 products, for the most part, are languishing. Here is an opportunity to refurbish them and bring them to buyers with suitable machines who know a bargain when they see it. “Suitable machines”, in my definition, include those with cassette storage, and are exemplified by the Amstrad CPC 464 (first year’s sales forecast of 200,000 units) which goes on sale in September 1984 at £239 for a complete hardware kit. But there are a great many others including the Sharp MZ711, RM390Z, Coleco Adam, Lynx, Spectravideo, the various MSX machines, and even that evergreen, updated, old-timer Apple IIe. Evenutally they will all have disk drives, but in the meantime many owners would be thankful for an interpreter containing even a subset of APL which will allow them to )SAVE a 10-20kb workspace on a separate cartridge.
Learning APL with an APLpip interpreter presents difficulties because every text-book on the subject shows the primitives in orthodox symbols. This is a real problem, but it shouldn’t be exaggerated. A good half of APLpip’s 38 ASCII substitutes are lookalikes and those that aren’t are mnemonic. At worst there is an additional burden of recognising a dozen different symbols and learning a new alphabet, something we all managed with ease in our kindergarten days. I believe the way to tackle this problem is to start “bilingually” with decals bearing the orthodox symbols affixed to the alphabetic keys. There should also be a “bilingual” introductory text. An orthodox one already exists priced at $2.95. Perhaps Messrs. Smith and Camacho would use their considerable communicative skills to create a “bilingual” version. Oh, and don’t forget to provide a PF (programmed function) key causing the unshifted alphabetic keys to be read as upper-case in APL mode and vice-versa in TEXT mode.
APLpip — APL/ASCII Character Mappings¶
![Typewritten table of APLpip mappings in five groups, with counts of characters and codes used: (1) inessentials not included (underscored alphabet, I-beam, alpha, omega, underbar, cap, cup, underbar delta, left and right tacks), 35 characters, 0 codes; (2) exact ASCII equivalents (space, A–Z, 0–9 and 19 punctuation and operator symbols), 56; (3) imitative and other symbols, 13 APL symbols mapped to & % _ | £ @ $ ` ^ ~ " { }; (4) lower-case alphabetic substitutes, 25, as imitative only (o r v x and c o p v x), imitative and mnemonic (e psilon, i ota, l ower style, t ake), mnemonic only with conventional names (d rop, j ot, m atrix inverse/divide, n ot, q uote quad, u pgrade) and with unconventional names (a ctuate, b igger/biggest, f alling sequence, g oto, h ead-over-heels, r eflect diagonally, s plit, w eave, y aw, z eroes in decimals); (5) compound substitutes [1] /[1] <= <> =>