TEACH DEMO                                       Aaron Sloman, June 1982


=== A VERY SHORT INTRODUCTION TO PROGRAMMING IN POP11 ==================

This assumes that you have been through the TEACH * MORE file, and  know
how to move the cursor  around, and how to  insert and delete text.  You
should know how to use the UPSCREEN and DOWNSCREEN buttons to read  this
file. You should be using a Visual 200 VDU.


-- STARTING TO EDIT YOUR OWN PROGRAM FILE ------------------------------

First you need to start a new  file using VED. For writing programs  you
will use  all the  VED  techniques you  have  already learnt.  The  only
difference is that  you should use  a file-name which  ends in '.P',  to
tell VED  that  the file  contains  programs, not  ordinary  text,  like
poetry.

So, if your  name is SALLY,  you can use  a file name  like SALLY.P,  or
SALLY5.P.

Get the file started with the actions:
    (a) Press the ENTER key
    (b) Type: ved sally5.p           (use your name in place of 'sally')
    (c) Press the RETURN key
    (d) Use ESC then LF to read more of this TEACH file.
    (e) Use ESC then BS to go back in this TEACH file.

Your file should be in  one half of the screen,  and this teach file  in
the other half. Practice using  ESC BS, then ESC  LF a couple of  times,
then read on.


-- MAKING POP11 DO SUMS ------------------------------------------------

You can  get  POP11 to  do  a calculation  for  you, by  typing  in  the
following line (or a similar line with different numbers):

    66 + 33 =>

Type exactly that, using the SHIFT key  to get the symbols '=' and  '>'.
That means 'Add 66 to 33 and print out the result'. It will not be  done
immediately. (Use ESC LF to read on.)

When you are sure you have typed it correctly, AND STILL HAVE CURSOR  ON
THAT LINE, you can make POP11  DO the command by the following  sequence
(ask for help if you get a 'mishap' message):

    (a) Push button F7 (which should be labelled Mark First)
            A mark will occur on the left of the line.
    (b) Hold down the CTRL button and press the D key once
            (This instruction will be abbreviated to CTRL-D, below).

When you press CTRL-D that tells the POP11 system to DO the instructions
which have been marked. Several things will happen.

The command line will show a message saying 'DOING 1 LINES' (sorry about
the grammar!). Then on the next line it will print out '**' followed  by
the answer. Finally the mark on the left will move to the line after the
printing, to  indicate that  that is  where you  should type  your  next
command.

Try that now if you haven't already. (Use ESC BS to go back if you don't
remember what to do.)

So when you have tried all that  and are ready for another command,  try
typing:

    25 * 2 =>

which tells POP11 to multiply 25 by  2 and print out the result. If  you
type with the cursor on the line which has a vertical mark at the  left,
then you  don't need  to press  the MARK  LINE button  (F7). Just  press
CTRL-D.

Try that now. (Use ESC BS to look back at the command.)


-- PRINTING LISTS OF WORDS ---------------------------------------------

Arithmetic can be rather boring, so here's something different.
Type in the following,  spread over three lines  (then read on with  ESC
LF):

    repeat 5 times
        [hi there] =>
    endrepeat;

If you start typing  on the line  marked by the  vertical bar, then  all
three lines will be automatically marked as the command to be obeyed.


-- MARKING A RANGE WITH KEYS F7 AND F8 ---------------------------------

If for any reason the lines you've  typed have not been marked with  the
vertical bar on the left, you can mark them yourself, thus (try it,  for
practice):

    (a) Move the cursor up (KEYPAD 8)  to the first line of the  command
        (i.e. the line with 'repeat 5 times')
    (b) Press  the F7  (Mark First)  button. That  makes that  line  the
        beginning of the marked range.
    (c) Move  the  cursor  down  (KEYPAD 2)  to  the  third  line  (with
        'endrepeat')
    (d) Press Key F8 (which should be labelled 'Mark Last')

At this stage you'll have your command marked on the left by a  vertical
bar, and nothing else should be  marked. You can get the command  obeyed
as before,  by  pressing CTRL-D.  (Ask  for help  if  you get  a  mishap
message.)

This should make the computer  obey the instruction '[hi there]=>'  five
times. As you will  see, this is  an instruction to make  a list of  two
words and print them out. (Eliza builds up its sentences by making lists
of words).


-- DELETING LINES OF 'OUTPUT' ------------------------------------------

Suppose you want to print out  something different. You can go back  and
edit the command, and get it obeyed  again. First, get rid of the  lines
with all the 'output', i.e. the lines starting with:

    '**'.

The easiest way to do this is to give the ENTER DELOUT command, thus:

    (a) Press the ENTER key
    (b) Type:  delout
    (c) Press the RETURN key

The lines with '**' will disappear  from your file (not from this  TEACH
file).


-- ALTERING THE PREVIOUS POP11 COMMAND ---------------------------------

Now move the cursor back into the 'repeat' command, and change it.  (Use
DEL to delete characters to  the left of the cursor,  and the key F0  to
delete characters under the cursor. You  can change the number of  times
the instruction is  to be  repeated (but don't  make it  very big,  e.g.
between 2 and 10 should do. You can also change the words to be  printed
out. E.g. you could put in something less polite, e.g.:

    repeat 4 times
        [go away you slob] =>
    endrepeat;

You can also make it print out  more than one list of words, by  putting
two print instructions before the endrepeat line, e.g.:

    repeat 4 times
        [ go away you slob] =>
        [ I am tired of you] =>
    endrepeat;

(To insert a line after  the line where the cursor  is, you can use  the
key marked  F13 (also  marked BL).  It should  be labelled,'Insert  line
BELOW').


-- MAKING YOUR NEW COMMAND WORK ----------------------------------------

First make sure that the whole of the command is marked by the  vertical
bar on the  left. If it  is not already  marked, put the  cursor on  the
first line and press the  MARK FIRST key (F7), then  put it on the  last
line and press the MARK LAST key  (F8). When the whole range is  marked,
you can do CTRL-D to get it obeyed.

Try a few variants,  using the ENTER  DELOUT command to  get rid of  the
output after each one.

If part of your file  goes off the screen and  you want to look back  at
it, you can use the UPSCREEN key.


-- HANDLING MISHAPS ----------------------------------------------------

You may already  have had  a mishap message.  You will  surely get  some
sooner or later as a result of  making a mistake of some sort:  everyone
does. Try to understand the  message, and if it  makes no sense ask  for
help. Then  correct  the program  and  carry  on. For  practice  do  the
following:

     99 66

Type that in. Make sure the line  is marked with a vertical bar on  left
(use F7 and F8 if necessary). Then press CTRL-D to get it obeyed.  POP11
does not allow  two numbers or  two words to  be typed without  anything
between them (except in the list brackets  [ .... ] as above. So  you'll
get a 'MISSING SEPARATOR' message. Try that, then use ESC LF to read on.

After that you can alter the offending bit of program, mark it and  have
it obeyed. E.g. you can change it to:

    99 + 66 =>

There are many  different sorts  of mishap messages,  depending on  what
sort of mistake has been  made. Ask for help  if you can't see  anything
you've done wrong. Simple mistakes will just produce a short message  on
the command line  at the top  of the window.  More complex mishaps  will
cause a longer message to  be printed at the  bottom of the screen,  and
you'll have to press RETURN to  get VED working again. You'll then  have
to do ENTER TEACH to make your teach file reappear on the screen,  after
you've done something about correcting the mistake.


-- DEFINING A PROCEDURE ------------------------------------------------

It is often very inconvenient to have  to go and edit a file every  time
you want  something different  to be  done. So  you can  define what  is
called a PROCEDURE, which  has a name, and  has some FIXED  instructions
and a VARIABLE part. You can run it by telling it what is to go in place
the the variable part.

Suppose we  want to  be able  to print  out different  lists,  different
numbers of times. The two variables are the list, and the number. We can
define a procedure called MULTIPRINT with two variables called LIST  and
NUM, thus

    define multiprint(list,num);
        repeat num times
            list =>
        endrepeat
    enddefine;

This defines a procedure called MULTIPRINT.

Type that in,  being very careful  about the semi-colons.  Use the  MARK
FIRST and MARK LAST buttons to mark the whole range. Then press  CTRL-D.
If you get  a mishap  message, try  to work  out what  you've not  typed
correctly, and alter  it. Use  the ENTER  D command  to get  rid of  the
mishap message, or ask for help if you don't understand it.

If you get no mishaps you  won't get any printout either. The  procedure
is stored away for future use, but the instructions are not obeyed  yet.
The computer will not know what list to print, and it will not know  how
many times to print it.  You can tell it this  by giving it a real  list
and a real number to replace the variables. Type in the following, being
careful about the difference between the round and square brackets.

    multiprint( [I like you], 4);

That means, obey the procedure called MULTIPRINT, using the list:

    [ I like you ]

to replace its first variable, and  the number 4 to replace its  second.
The  semi-colon  says  this  is   the  end  of  the  instruction   (some
instructions can be more complex, and can go over several lines, so  the
';' is needed to say there's no more coming.)

When you've typed in that command,  you can mark it (if necessary),  and
then type CTRL-D to get it obeyed.


-- THE SAME PROCEDURE RUN WITH DIFFERENT INPUTS ------------------------

Note that the original procedure has not been altered. Rather, it is  as
if a temporary COPY has been made with the variables replaced, and  then
the instructions obeyed. You can get it obeyed with different values for
the variables:

    multiprint([computers are lovely], 8);


-- MIXING FIXED AND VARIABLE LISTS -------------------------------------

The procedure multiprint is rather unoriginal in what it prints out.  It
just prints out exactly what you give  it. We can make a more  elaborate
procedure which constructs a new list of words to print out.

We need the concept  of merging a  fixed list of  words with a  variable
part.

Suppose we want  to make  several different  lists with  a common  part,
e.g.:

    [hello fred nice to meet you]
    [hello uncle joe nice to meet you]
    [hello mary ann nice to meet you]

The fixed bit is:

    [hello ... nice to meet you]

The variable bit can be given a name, like the variables we used before,
LIST and NUM. Let's call this one NAME. But we can't just write:

    [hello name nice to meet you]

because there is nothing to  say that the word  'name' is to be  treated
any differently from the other words in the list. So we put the  special
symbol:

    ^^

in front of it to tell POP11 that the word "name" is not to go into  the
list, but something not yet specified.

    [hello ^^name nice to meet you]

We can use that in the following procedure. Type it in:

    define multigreet(name, num);
        repeat num times
            [hello ^^name nice to meet you]
        endrepeat
    enddefine;

Copy it in very carefully. Notice that we don't need to put '^^'  before
the occurrence of 'num' in the second line because it is not in a  list.
Mark the procedure and type CTRL-D to get it 'compiled'.

Its name is MULTIGREET and it has two input variables (sometimes  called
'arguments'). One  represents a  list, and  one a  number. As  with  the
previous procedure MULTIPRINT, you  can get it  obeyed by giving  values
for the  variables,  by writing  the  name the  procedure,  followed  by
parentheses containing the values, then a semi colon. Type in:

    multigreet( [ father christmas ], 4);

Then mark the command and type CTRL-D. If you get a MISHAP ask for  help
if you  can't see  what has  gone wrong.  Correct the  command, Mark  it
again, and type CTRL-D again.

Now try with your own name between the list brackets.


-- MAKING SENTENCES ----------------------------------------------------

The rest of this file  is best tried only  if you have fully  understood
everything so  far,  and  feel  confident  that  you  understand  what a
procedure is.

We are going to make a procedure which creates sentences of the form:

            subject verb object

Where the subject is a Noun Phrase, and so is the object.

The SENTENCE procedure will rely on  a procedure called NPHRASE to  make
noun phrases, and a procedure  called VERB to construct verbs.  SENTENCE
will put them all together.

All the procedures will use the built in POP11 procedure ONEOF to select
(at  random)  from  a  list  of  alternatives.  Type  in  the  following
procedures. You'll need to  be very careful  about getting the  brackets
right. Notice that these procedures  don't have any variable inputs,  so
we write '()' after the name.

    define nphrase();
       oneof([ [the old man] [a silly grey dog] [you] [every visitor] ])
    enddefine;

When you've typed  it in,  mark the  range, and  type CTRl-D  to get  it
compiled. Do the same with the following:

    define verb();
        oneof([ [ate] [jumped over] [looked at] [liked] [hated] ])
    enddefine;

    define build(subject, verb, object);
        [^^subject ^^verb ^^object]
    enddefine;

    define sentence();
        build(nphrase(), verb(), nphrase() )
    enddefine;

Notice that  the  procedure  called BUILD  has  three  variable  inputs.
SENTENCE gives it  three inputs,  the first from  NPHRASE(), the  second
from VERB() and the third from NPHRASE() again.

None of the  procedures uses  the printout  arrow symbol  '=>'. That  is
because they were not required to print anything out, but to leave their
lists in the computer,  ready for use by  other procedures. You can  now
run SENTENCE and get it to print out its list, as follows:

    sentence() =>

Type that mark it and CTRL-D to do it. Then try:

    repeat 5 times sentence() => endrepeat;

If you  want  to change  one  of the  procedures,  e.g. by  telling  the
procedure VERB about more  verbs, you can go  back (using SCREENUP  key,
and keypad  keys) and  alter  the definition.  Make  sure you  keep  the
brackets consistent, however. (A pair of list brackets [ ... ] for every
phrase, and then  another pair at  the extremes  to make a  list of  the
lists.) Having  changed your  procedure,  you can  mark  it and  get  it
compiled with CTRL-D, then give  your 'repeat 5 times...' command  again
by putting the cursor on it, marking it, and then CTRL-D to do it.


-- CONCLUSION ----------------------------------------------------------

In a more elaborate program, the  procedures NPHRASE and VERB would  not
have built  in  lists  of  alternatives, but  would  'call'  still  more
sub-procedures to construct the required  phrases. Making a computer  do
this in a  sensible way requires  us to have  a good theory  of how  the
English language works. That is one of the central areas of research  in
the field of Artificial Intelligence.

If you want to print out your file:

    press ENTER
    type: print
    press RETURN.

Ask one of the demonstrators to help you get the paper from the printer.
Then finish off,

    press ENTER
    type : xx
    press RETURN

--- C.all/teach/demo ---------------------------------------------------
--- Copyright University of Sussex 1987. All rights reserved. ----------
