Skip to content

Introducing APL to Teachers

Vector 8:3, page 19

education

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:

      5+4
9
      'TEXT'
TEXT

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:

      HIM←'GEORGE BUSH'

Now we are ready to start "programming". Actually the process is called DEFINING A FUNCTION.

We begin with PLUS, the simplest function of all

      PLUS: ⍺+⍵

The symbol ⍺ means "use the values to the left of" +, and the symbol ⍵ means use everything to the right. Now let us try it!

      4 PLUS 3
7
      2 PLUS 1 2 3
3 4 5
      1 2 3 PLUS 5
6 7 8

What do we mean when we say: ⍺ means "use values to the left of"?

      10×1 2 3 PLUS 5
60 70 80

⍺ STOPS when it finds something other than a valid value.

Now we can define MINUS:

      MINUS: ⍺-⍵
      4 MINUS 3
1
      4 PLUS 2 MINUS 5
1

We could go on and define TIMES and DIVIDE, but let us now look at text:

      HIM
GEORGE BUSH
      ME←'PAUL GARCIA'
      ME
PAUL GARCIA

We will define the function REVERSE:

      REVERSE: ⌽⍵
      REVERSE ME
AICRAG LUAP

Can we use REVERSE with numbers? We sure can!

      REVERSE 3 4 5
5 4 3
      NOS←1 2 3 4 5
      NOS PLUS REVERSE NOS
6 6 6 6 6

But let us return to "text" processing:

      VOWELS:(⍵∊'AEIOUY')/⍵
      VOWELS ME
AUAIA

You may want to use a DUMMY function like IN, to do nothing:

      IN:⍵
      VOWELS IN ME
AUAIA

Let us define some more FUNCTIONS:

      TABLE: ⍺⍴⍵
      FLIP: ⍉⍵

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:

      WORDS[3;3]←'T'

(I-APL unfortunately does not support an easier way to do that.)

Now let us go back to numbers:

      COUNT: ⍳⍵
      ODDS: (2×COUNT ⍵)-1
      SUM: +/⍵

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.