Search                        Top                                  Index
TEACH PROCEDURES                                               A. Sloman

=== PROCEDURES IN POP11 ================================================

Procedures are 'packaged' sets of instructions, usually with a name. For
example, the arithmetic operation + is a procedure, whose name is "+". It
can be used in a command, to make POP11 do something.

For example

    2 + 3

is a command to tell POP-11 to add the numbers 2 and 3, producing the
result 5. We call the numbers 2 and 3 ARGUMENTS of the procedure
(sometimes called INPUTS, or PARAMETERS) and the number 5 the RESULT
(sometimes called the OUTPUT).

The instructions which enable the computer to obey this command, were
built in by the makers of the computer and the people who programmed the
POP-11 system.

So + is one example among many procedures which are 'built in' to POP-11,
ready for you to use.

However, for many problems it is not enough to use the built-in
procedures. In addition you need to create new procedures of your own, to
avoid having constantly to retype instructions.

E.g. suppose you constantly were measuring the sides of rectangles and
wanted to work out the perimeter in each case.

                -------------
                |           |
                |           |
                -------------

You find the perimeter by adding the lengths of all the sides. But since
two of them are repeated, you can add them twice over, thus

    define perim(width,height) -> total;
        width + width + height + height -> total
    enddefine;

This introduces a new procedure, which has two ARGUMENTS (here called
width and height) and one RESULT, here called total. If you type that in
to POP-11, then you can subsequently use "perim" as a name for this
procedure. That is, you have essentially extended the language. So if you
type

    perim(365,732)

this will be interpreted as a command to do

    365 + 365 + 732 + 732

Of course, this procedure doesn't save you very much typing, except
perhaps when the two numbers are rather big

    perim(9876543, 3456789)

compared with

    9876543 + 9876543 + 3456789 + 3456789

But you will find out later that procedures can include quite long lists
of instructions, and can be much more varied in their behaviour, for
instance if they include "conditional" instructions.

Later you will find out how the results produced by one procedure can be
used as arguments (inputs) to another, or stored in a variable, or printed
out.

You can get an introduction to POP-11 procedures from the following TEACH
files:

TEACH * VEDPOP, *RIVER, *DEFINE, *RESPOND

TEACH * DEFINE summarises different ways you can define procedures.

When you have finished reading this file press the ESC button then Q.