References
[1] Ian Clark, “Review of Mathematica 5.2” Vector 22.4, pp60-78
[2] Roger Hui, “A Lifetime of Working with Ken” Vector 22.3, pp94-108
[3] David Crystal, The Cambridge Encyclopedia of Language, C.U.P., 1987, ISBN 0-521-42443-7
[4] Jan Gullberg, Mathematics from the Birth of Number, 1997, Norton & Co., ISBN 0-393-04002-X
[5] Cornelius Lanczos, Applied Analysis, Pitman, 1957, London.
[6] Kenneth E. Iverson, “APL in the New Millenium” Vector 22.3, pp5-12
[7] Donald McIntyre, “The Perils of Subtraction” Vector 11.4
[8] Gérard Langlet, letter Vector 12.1
Discover
APL – A Glimpse of Heaven
by Bernard Legrand (bernard.legrand@interfluences.fr)
translated by Sylvia Camacho
This document was created for a conference on 22 June 2006, organized by AFAPL, Association Francophone pour la promotion du langage APL: a special conference dedicated to our friend Henri Sinturel, now no longer with us.
This conference was not designed for those proficient in the language: their needs have been met for many years and I have nothing to teach them. I am only attempting to demonstrate this attractive intellectual tool to those who do not know it, in the hope of making one or two converts willing to promote it.
In fact the following presentation is intended, above all, to construct a bridge between two generations:
The “diplodocus” generation familiar with information technology before the PC and the advent of screens (remember, they were the same ones who knew about punched cards!) and who found in APL a means of handling all the problems which large computers could not handle within a reasonable time. That generation is on the way to extinction.
The generation who know only about micro-computers, the Internet and hypertext; on which they have been brought up, with substantial help from Excel, ever since their schooldays and who would like to think everything can be done with three clicks of a mouse.
But to describe the APL language, whether in 3 pages or 30, is as difficult as describing a tennis match or the flight of a seagull: a written document is not capable of matching hands-on experience. Thus the following pages only give a very limited and fragmentary view of the whole wealth of APL.
The abundance of APL riches is a glimpse of heaven. Here’s to you, Henri!
I hope to stay true to the spirit of APL, and to the enthusiasm of those who have praised and promoted it over the years. I shall try also to reply to the most frequently asked questions and the most often expressed criticisms, but I cannot encompass all aspects of the debate. So I invite all those who are curious about the language to spend an hour with me at a computer screen.
Fasten your seatbelts: we’re off!
The First Step is Easy
In the following pages, for maximum clarity, the text typed in by the user is indented, whereas the computer’s response begins at the left margin.
The first impression of APL is that of a hand calculator:
27 + 53
80
1271 – 708
562
59 × 8
475
86 ÷ 4
21.5
The first surprise is that multiplication is represented by its proper symbol × and not by the abominable star * which prevails in all other computer languages. The same goes for division.
To create a variable it is enough to key in the chosen name and to show by the arrow ← that it is to be given the value or values which follow.
For example:
VAT ← 19.6 ⍝ read as: VAT gets 19.6
Years ← 1952 1943 1986 2005
To learn the contents of a variable it is sufficient to type its name thus.
Years
1952 1943 1986 2005
A Global Approach
It is characteristic of APL that it can operate simultaneously on two sets of numbers of the same “shape”. Below, for example, there are two variables, a list of prices of 5 products and the quantity bought of each:
Price ← 5.2 11.5 3.6 4 8.45
Qty ← 2 1 3 6 2
When the two variables are multiplied together, they are multiplied item by item to produce a result of the same shape:
Costs ← Price × Qty
Costs
10.4 11.5 10.8 24 16.9
This global approach eliminates most of the “loops” which greatly overburden programs in most current languages.
This property remains true for arrays of values of the same shape or number of dimensions.
So a Sales Director can make forecasts for sales of 4 products over the coming 6 months, and assign them to the variable Forecast.
At the end of 6 months he can assign the somewhat different real values to the variable Actual.
Forecast Actual
150 200 100 80 80 80 141 188 111 87 82 74
300 330 360 400 500 520 321 306 352 403 497 507
100 250 350 380 400 450 118 283 397 424 411 409
50 120 220 300 320 350 43 91 187 306 318 363
It is clear that the first reaction of our Director will be to evaluate the differences, which he can get very easily by writing:
Actual-Forecast
¯9 ¯12 ¯11 7 2 ¯6
21 ¯24 ¯8 3 ¯3 ¯13
18 33 47 44 11 ¯41
¯7 ¯29 ¯33 6 ¯2 13
Note that the sign is part of the number. Negatives take a high minus to distinguish the sign of a negative value from subtraction.
To get a similar result by means of a traditional computer language requires many instructions, which hides the object of the calculation behind arcane programming. Here, for example, is what one would write in PASCAL:
DO UNTIL I=4
DO UNTIL J=6
DIFF(I,J):=ACTUAL(I,J)-FORECAST(I,J)
END
END.
Ah well, believe it or not, one can find at the heart of French university establishments people who maintain that the second way of writing these things is the simplest, those who resurrect the well-known Shadoks maxim: [Trans: a 1960s French cult animation series, according to Google]: Why make it simple when one can make it complicated?
We have seen that APL works between two variables of the same shape; it also works between such variables and a single item, which is called a scalar.
Such will be the case if one wants to calculate the total of 19.6% VAT applied to the variable Price above.
Whether one writes Price × 0.196 or one writes 0.196 × Price the result will be the same:
1.0192 2.254 0.7056 0.784 1.6562
A result which will require rounding, but that is not important here.
Share with your friends: |