The Inductive Method of Introducing APL
Because APL is a language, there are, in the teaching of it, many analogies with the teaching of natural languages. Because APL is a formal language, there are also many differences, yet the analogies prove useful in suggesting appropriate objectives and techniques in teaching APL.
For example, adults learning a language already know a native language, and the initial objective is to learn to translate a narrow range of thoughts (concerning immediate needs such as the ordering of food) from the native language in which they are conceived, into the target language being learned. Attention is therefore directed to imparting effective use of a small number of words and constructs, and not to the memorization of a large vocabulary. Similarly, a student of APL normally knows the terminology and procedures of some area of potential application of computers, and the inital objective should be to learn enough to translate these procedures into APL. Obvious as this may seem, introductory courses in APL (and in other programming languages as well) often lack such a focus, and concentrate instead on exposing the student to as much of the vocabulary (i.e., the primitive functions) of APL as possible.
This paper treats some of the lessons
to be drawn from analogies
with the teaching of natural languages
(with emphasis on the inductive method of teaching),
examines details of their application in the development
of a three-day introductory course in APL,
and reports some results of use of the course.
Implications for more advanced courses
are also discussed briefly.
1. The Inductive Method
Grammars present general rules, such as for the conjugation of verbs, which the student learns to apply (by deduction) to particular cases as the need arises. This form of presentation contrasts sharply with the way the mother tongue is learned from repeated use of particular instances, and from the more or less conscious formulation (by induction) of rules which summarize the particular cases.
The inductive method is now widely used in the teaching of natural languages. One of the better-known methods is that pioneered by Berlitz  and now known as the “direct” method. A concise and readable presentation and analysis of the direct method may be found in Diller .
A class in the purely inductive mode is conducted entirely in the target language, with no use of the student’s mother tongue. Expressions are first learned by imitation, and concepts are imparted by such devices as pointing, pictures, and pantomime; students answer questions, learn to ask questions, and experiment with their own statements, all with constant and immediate reaction from the teacher in the form of correction, drill, and praise, expressed, of course, in the target language.
In the analogous conduct of an APL course, each student (or, preferably, each student pair) is provided with an APL terminal, and with a series of printed sessions which give explicit expressions to be “imitated” by entering them on the terminal, which suggest ideas for experimentation, and which pose problems for which the student must formulate and enter appropriate expressions. Part of such a session is show as an example in Figure 1.
Because APL is an “imperative” language, the APL system can execute any expression entered on the terminal, and therefore provides most of the reaction required from a teacher. The role of the instructor is therefore reduced to that of tutor, providing explicit help in the event of severe difficulties (such as failure of the terminal), and general discussion as required. As compared to the case of a natural language, the student is expected, and is better able, to assess his own performance.
Applied to natural languages, the inductive method offers a number of important advantages:
Analogous advantages are found in the teaching of APL:
2. The Use Of Reference Material
In the pure use of the inductive method, the use of reference material such as grammars and dictionaries would be forbidden. Indeed, their use is sometimes discouraged because the conscious application of grammatical rules and the conscious pronunciation of words from visualization of their spellings promotes uneven delivery. However, if a student is to become independent and capable of further study on his own, he must be introduced to appropriate reference material.
Effective use of reference material requires some practice, and the student should therefore be introduced to it early. Moreover, he should not be confined to a single reference; at the outset, a comprehensive dictionary is too awkward and confusing, but a concise dictionary will soon be found to be too limited.
In the analogous case of APL, the role of both grammar
and dictionary is played by the reference manual.
A concise manual limited to the core language
should be supplemented by a more comprehensive manual
(such as Berry
which covers all aspects of the particular system in use.
Moreover, the student should be led immediately
to locate the two or three main summary tables
in the manual,
and should be prodded into constant use
of the manual by explicit questions
(such as “what is the name
of the function denoted by the comma”),
and by glimpses of interesting functions.
3. Order Of Presentation
Because the student is constantly striving to impose a structure upon the examples presented to him, the order of presentation of concepts is crucial, and must be carefully planned. For example, use of the present tense should be well established before other tenses and moods are introduced. The care taken with the order of presentation should, however, be unobtrusive, and the student may become aware of it only after gaining experience beyond the course, if at all.
We will address two particular difficulties with the order of presentation, and exemplify their solutions in the context of APL. The first is that certain expressions are too complex to be treated properly in detail at the point where they are first useful. These can be handled as “useful expressions” and will be discussed in a separate section.
The second difficulty is that certain important notions are rendered complex by the many guises in which they appear. The general approach to such problems is to present the essential notion early, and return to it again and again at intervals to reinforce it and to add the treatment of further aspects.
For example, because students often find difficulty with the notion of literals (i.e., character arrays), its treatment in APL is often deferred, even though this deferral also makes it necessary to defer important practical notions such as the production of reports. In the present approach, the essential notion is introduced early, in the manner shown in Figure 2. Literals are then returned to in several contexts: in the representation of function definitions; in discussion of literal digits and the functions (⍕ and ⍎) which are used to transform between them and numbers in the production of reports; and in their use with indexing to produce barcharts.
Function definition is another important idea whose treatment is often deferred because of its seeming complexity. However, this complexity inheres not in the notion itself, but in the mechanics of the general del form of definition usually employed. This complexity includes a new mode of keyboard entry with its own set of error messages, a set of rules for function headers, confusion due to side-effects resulting from failure to localize names used or to definitions which print results but have no explicit results, and the matter of suspended functions.
All of this is avoided by representing each function definition by a character vector in the direct form of definition [5 6]. For example, a student first uses the function round provided in a workspace, then shows its definition, and then defines an equivalent function called r as follows:
round 24.78 31.15 28.59 25 31 29 show 'round' round:⌊.5+⍵ define 'r:⌊.5+⍵' r 24.78 31.15 25 31
The function define compiles the definition provided by its argument into an appropriate del form, localizes any names which appear to the left of assignment arrows in the definition, provides a “trap” or “lock” appropriate to the particular APL system so that the function behaves like a primitive and cannot be suspended, and appends the original argument in a comment line for use by the function show .
This approach makes it possible
to introduce simple function definition
very early and to use it in a variety
of interesting contexts
before introducing conditional
and recursive definitions (also in the direct form),
and the more difficult del form.
4. Teaching Reading
It is usually much easier to read and comprehend a sentence than it is to write a sentence expressing the same thought. Inductive teaching makes much use of such reading, and the student is encouraged to scan an entire passage, using pictures, context, and other clues, to grasp the overall theme before invoking the use of a dictionary to clarify details.
Because the entry of an APL expression on a terminal immediately yields the overall result for examination by the student, this approach is particularly effective in teaching APL. For example, if the student’s workspace has a table of names of countries, and a table of oil imports by year by country by month, then the sequence:
n←25 b←+/[l]+/ oil countries,'.⎕'[1+b∘.≥(⌈/b)×(⍳n)÷n]
produces the following result, which has the obvious interpretation as a barchart of oil imports:
Arabia ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕..... Nigeria ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕...... Canada ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕......... Indonesia⎕⎕⎕⎕⎕⎕⎕⎕⎕................ Iran ⎕⎕⎕⎕⎕⎕⎕⎕................. Libya ⎕⎕⎕⎕⎕⎕⎕⎕................. Algeria ⎕⎕⎕⎕⎕⎕⎕⎕................. Other ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Moreover, because the simple syntax makes it easy to determine the exact sequence in which the parts of the sentence are executed, a detailed understanding of the expression can be gained by executing it piece-by-piece, as illustrated in Figure 3. Finally, such critical reading of an expression can lead the student to formulate his own definition of a useful related function as follows:
define ⍞ barchart:'.⎕'[1+⍵∘.≥((⍳⍺)÷⍺)×⌈/⍵]
5. Useful Expressions
As remarked in Section 3, some expressions are too useful and important to be deferred to the point that would be dictated by the complexity of their structure. In APL such expressions can be handled by introducing them as defined functions whose use may be grasped immediately, but whose internal definition may be left for later study.
For example, files can be introduced in terms of the functions get , to , range , and remove , illustrated in Figure 4. These can be grasped and used effectively by the student at an earlier stage and with much greater ease than can the underlying language elements from which they must be constructed in most APL systems.
A further example is provided by the function needed to compile, display, and edit the character vectors used in direct definition of functions. For example, an editing function which deletes each position indicated by a slash, and inserts ahead of the position of the first comma any text which follows it (in the manner provided for del editing in many APL systems) is illustrated in Figure 5.
Deferral of the internal details of the definition of these essential functions can, in fact, be turned to advantage, because they provide interesting exercises in reading (using the techniques of Section 4) the definitions of functions whose purposes are already clear from repeated use. For example, critical reading of the following definition of the function edit is very helpful in grasping the important idea of recursive definition:
edit:edit(a delete k↑⍵),(1↓k↓a),(k←+/∧\a≠',')↓⍵:0=⍴a←⍞,0⍴⎕←⍵:⍵ delete:(~(⍴⍵)↑'/'=⍺)/⍵
Analysis of the complete set of functions
provided for the compilation
from direct definition form
also provides an interesting exercise in reading,
but one which would not be completed,
or perhaps even attempted,
until after completion
of an introductory course.
Extensive leads to other interesting reading,
of both workspaces and published material,
should be given the student to encourage
further growth after the conclusion
of formal course work.
Advanced language courses can also employ the inductive method, but the greater the student’s mastery of a language, the greater the potential benefits of the deductive approach and of explicit analysis of the structure of the language. A point sometimes made in the advanced treatment of natural languages is that grammar and related matters can now be discussed in the target language, avoiding distractions and distortions which might be introduced by use of the mother tongue.
Similar remarks apply to advanced APL courses.
In particular, the use of APL in its own discussion
and in the introduction of the more complex functions
is quite productive.
For example, reduction is very useful in discussing
the inner product, and inner product and grade
are helpful in analyzing dyadic transpose.
Conduct Of The Course
The introductory course on which these remarks are based evolved through four versions offered over a period of several months. The resulting course covers three contiguous days, and has been offered a number of times in the final form.
Most students appear to work better in pairs
than when assigned individually to terminals.
Because there are no lectures,
each pair can work their own pace.
Observations and student comments show that
they find it more stimulating than a lecture course,
and tend to come early and work late.
Moreover, they learn to consult manuals
much more than in a lecture course,
and exhibit a good deal of independence
by the end of the three days.
I am indebted to a number of my colleagues
at I.P. Sharp Associates, to Mr. Roland Pesch
for his development of the file functions used,
to Mr. Pesch and Mr. Michael Berry for assistance
and advice in the early version of the course,
and the Ms. Nancy Neilson and Dr. Paul Berry
for comments arising from their use of the course.
I am also indebted to several members of the staff
of the Berlitz School of Languages in Toronto,
to Ms. Grace Palumbo and Ms. G. Dunn
for discussions of the direct method,
and to Ms. N. Eracleous
for patient demonstrations of it.
Originally appeared in the proceedings of the APL Users Meeting, I.P. Sharp Associates Limited, Toronto, 1980-10-06 to 08.