The Inductive Method of Introducing APL

Kenneth E. Iverson
I.P. Sharp Associates
Toronto, Ontario

 

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 [1] and now known as the “direct” method. A concise and readable presentation and analysis of the direct method may be found in Diller [2].

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.

Session 1: Names and Expressions

The left side of each page provides examples to be entered on the keyboard, and the right side provides comments on them. Each expression entered must be followed by striking the RETURN key to signal to the APL system to execute the expression.

   area←8×2The name area is assigned to the
   height←3result of the multiplication, that is 16
   volume←height×area 
   height×areaIf no name is assigned to the result,
48it is printed
   volume 
48 
   3×8×2 
48 
   length←8 7 6 5Names may be assigned to lists
   width←2 3 4 5 
   length×width 
16 21 24 25 
   perimeter←2×(length+width) Parentheses specify the order in which
   perimeterparts of an expression are to be
20 20 20 20executed
   1.12×1.12×1.12Decimal numbers may be used
1.404928 
   1.12*3Yield of 12 percent for 3 years
1.404928 

Sample Portion of Session
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:

1.  Many dull but essential details (such as pronunciation) required at the outset are acquired in the course of doing more interesting things, and without explicit drill in them.
2.  The fun of constantly looking for the patterns or rules into which examples can be fitted provides a stimulation lacking in the explicit memorization of rules, and the repeated examples provide, as always, the best mnemonic basis for remembering general rules.
3.  The experience of committing error after error, seeing that they produce no lasting harm, and seeing them corrected through conversation, gives the student a confidence and a willingness to try that is difficult to impart by more formal methods.
4.  The teacher need not be expert in two languages, but only in the target language.

Analogous advantages are found in the teaching of APL:

1.  Details of the terminal keyboard are absorbed gradually while doing interesting things from the very outset.
2.  Most of the syntactic rules, and the extension of functions to arrays, can be quickly gleaned from examples such as those presented in Figure 1.
3.  The student soon sees that most errors are harmless, that the nature of most are obvious from the simple error messages, and that any adverse effects (such as an open quote) are easily rectified by consulting a manual or a tutor.
4.  The tutor need only know APL, and does not need to be expert in areas such as financial management or engineering to which students wish to apply APL, and need not be experienced in lecturing.
 

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 [3] should be supplemented by a more comprehensive manual (such as Berry [4]) 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.

Session 4: Literals

   Janet←5Janet received 5 letters today
   Mary←8 
 
   Mary⌈JanetThe maximum received by one of them
8 
   Mary⌊Janet    The minimum
5 
   Mary>Janet    Mary received more than Janet
1 
   Mary=Janet    They did not receive an equal number
0 

What sense can you make of the following sentences:

   Janet has 5 letters and Mary has 8

   Janet has 5 letters and Mary has 4

   'Janet' has 5 letters and 'Mary' has 4

The last sentence above uses quotation marks in the usual way to make a literal reference to the (letters in the) name itself as opposed to what it denotes. The second points up the potential ambiguity which is resolved by quote marks.

   list←24.6 3 17
   ⍴list
3
   word←'list'
   ⍴word
4
   sentence←'list the net gains'

Introduction of Literals
Figure 2

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]+/[3] 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+⍵∘.≥((⍳⍺)÷⍺)×⌈/⍵]

   nThe width of the barchart
25
   q←(⍳n)÷nNumbers from 0 to 1 in 25 equal steps
     (display if desired)
   ⌈/bThe largest value to be charted
   c←(⌈/b)×qNumbers from 0 to the largest value to be charted
 
   s←b∘.≥cComparison of each value of b with each value
   sin the range to be charted
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
   3 21↑1+sExamine a piece of 1+s
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1

Detailed Execution of an Expression
Figure 3


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.
 

If the first dimension of an array (list, table, or list of tables) has the value n , (for example, 1↑⍴oil is 7), then it may be distributed to n items of a file by a single operation. For example:

   oil to 'imports 72 73 74 75 76 77 78'

Use the function get to retrieve individual items from the imports file to verify the effect of the preceding expression.

   counries to 'imports 1'    Non-numeric data may be entered

The functions range and remove are useful in managing files:

   range 'imports'            Gives range of indices
1 72 73 74 75 76 77 78

   remove 'imports 73 75 77'  Remove odd years

   range 'imports'
1 72 74 76 78

Functions for Using Files
Figure 4


   text←'ddellletn and insrtion'
   z←edit text          Apply edit to erroneous text
ddellletn and insrtion          Line printed by the function
/   //  ,io             Line entered on the keyboard
deletion and insrtion           Line printed by the function
                ,e      Line entered on the keyboard
deletion and insertion          Line printed by the function
                        Empty line entered on the keyboard
                        (carriage return alone) ends execution of edit

   define 'revise:define edit show ⍵'
                        Define a function for revision

   revise 'sum'
sum:+/[⍺]⍵
///,max
max:+/[⍺]⍵
    /,⌈
max:⌈/[⍺]⍵

Functions for Editing and Revision
Figure 5


Advanced Courses

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.
 

Acknowledgements

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.
 

References

[1]  Berlitz, M.D., Methode Berlitz, Berlitz and Co., New York, 1887.
[2]  Diller, Karl Conrad, The Language Teaching Controversy, Newbury House Publishers, Inc., Rowley, Massachusetts, 1978.
[3]  APL Language, IBM Form #GC26-3847, IBM Corporation.
[4]  Berry, P.C., SHARP APL Referrence Manual, I.P. Sharp Associates.
[5]  Iverson, K.E., Elementary Analysis, APL Press, 1976.
[6]  Iverson, K.E., Programming Style in APL, An APL Users Meeting, I.P. Sharp Associates, 1978.



Originally appeared in the proceedings of the APL Users Meeting, I.P. Sharp Associates Limited, Toronto, 1980-10-06 to 08.

created:  2009-07-21 09:15
updated:2013-07-23 22:10