Introducing APL to Teachers
Vector 8:3, page 19
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 19
Computers as a Tool for Thinking¶
The purpose of this DEMO is threefold:
3. To show a proposed sample session in class
2. To program in front of you EVERY step of the session
1. To ask you, the experts, to tell us how to improve this session
Because of the ease of programming, I hope that you will consider learning how to use this instructional language. (To get very proficient at it does take more time and effort.) At the high school level, I would even suggest some of the students learn it.
The screen of this PC can be used in much the same way as you would a blackboard:
You write numeric expressions in the normal way, but must place text in quotes. The computer "EVALUATES" your expression, and prints the RESULT on the next line.
If you do not want to see the RESULT, you can divert it to a VARIABLE:
Now we are ready to start "programming". Actually the process is called DEFINING A FUNCTION.
We begin with PLUS, the simplest function of all
The symbol ⍺ means "use the values to the left of" +, and the symbol ⍵ means use everything to the right. Now let us try it!
What do we mean when we say: ⍺ means "use values to the left of"?
⍺ STOPS when it finds something other than a valid value.
Now we can define MINUS:
We could go on and define TIMES and DIVIDE, but let us now look at text:
We will define the function REVERSE:
Can we use REVERSE with numbers? We sure can!
But let us return to "text" processing:
You may want to use a DUMMY function like IN, to do nothing:
Let us define some more FUNCTIONS:
Now let us see what we can do with these:
WORDS←3 3 TABLE 'GEMAREBAN'
WORDS
GEM ARE BAN
REVERSE WORDS
MEG ERA NAB
FLIP WORDS
GAB ERA MEN
REVERSE FLIP WORDS
BAG ARE NEM
You could try to have students find words that mean something backward and forward. They can change any letter in table WORDS with the following expression:
(I-APL unfortunately does not support an easier way to do that.)
Now let us go back to numbers:
Note that in defining ODDS, we used the previously defined COUNT. You can even define a function that uses itself! But now, let us see what these functions will do:
COUNT 10
1 2 3 4 5 6 7 8 9 10
ODDS 10
1 3 5 7 9 11 13 15 17 19
SUM COUNT 10
55
SUM ODDS 9
81
SUM ODDS 8
64
As you can see we could go on studying the functions we already defined, or define even more functions. You could write your own lessons, if you would be willing to learn about those special symbols and how they work.