.fo 'Aaron Sloman''25 August 1977'
.he 'HELLO''Page %'

.ce 2
STARTING POP11
======== =====

If you have not previously played with a teletype, or if your typing is
very bad, you may find it helpful to ask the computer for a little typing lesson.

To do this, first log in (ask for help if you don't know how), then, when
the POP11 system has announced itself, you type
   TTT;
.br
and press the button marked "cr", or "return", or "linefeed". The computer
will tell you what to do after that.

When you feel reasonably confident about typing, come back to this and read
on.

If there's nobody to help you when you start, you should read the
notice on the notice-board entitled:
.ce 1
"USE OF TERMINALS WITH POP11 AND UNIX"

Don't worry if you cannot remember it all. The main points
are:
.nf
.in+5
end each line with button marked "return","CR" or "newline"
delete mistyped symbols with button marked "rubout" or "delete"
to cancel whole line, hold down CTRL and type U
when you've finished hold down CTRL and type D
the "interrupt" command is to hold down CTRL and type X
.in -5
.fi

.mh9
Conversing with the computer
----------------------------
.hm
Log in and wait for the POP11 system to greet you. When it types a colon at you, thus
 	:
.br
this means the POP11 system is ready, waiting for you to type something in.
The colon is called a "prompt". Different programs use different prompts,
but for the present you'll meet only this prompt.

In the examples given below, the colon is shown, but you do not type it. What
follows the colon is what you should type. So, type this:

 	: LIB HELLO;

(Don't forget to end by pressing the button marked "CR" or "return" or "newline".)
.br
This asks the POP11 system to load a library program called HELLO.
It will print out a brief message saying that it is loading the program.
When you get the colon prompt, you can run the HELLO program by typing:
 	: HELLO();
.br
which means, please run (execute, obey) the function (program)
called HELLO. Try it. When the computer asks you your name
type it in, following by the button marked "return" or "CR" or "linefeed".
You can repeat this as many times as you like, giving different names.

What follows will lead you up to the point where you can create a program like
the HELLO program. You'll learn to do lots of other things on the way.

Let's start by getting used to some of the basic building blocks which you'll
use to construct the program.
Type the following, and see what happens:
 	: [HELLO THERE] =>

That was a command to the computer to make a list containing two words,
and to print it out. The square brackets "[" and "]" mean "make a list", and
the "print-arrow", "=>" means, roughly "print out what you've just created".
What the computer prints in response to "=>" is preceded by two asterisks.

Try a different list, e.g.:

 	: [WHO ARE YOU?] =>
 	: [1 ONE 2 TWO 3 THREE] =>
.br

Try some more of your own.

Instead of giving the full instruction every time, you can define a "function",
i.e. a little program which when executed will obey a series of instructions
you have specified. Here is a definition of a simple function called HI. Type
it in:

.ne 4
 	: FUNCTION HI();
 	:	[HI THERE] =>
 	:	[WHO ARE YOU?] =>
 	: END;
.br

If anything goes wrong you'll get an error message, followed by "SETPOP",
after which you can re-type the function.

.in +5
NOTE:
.br
Each error message includes a number and a brief explanation.
If you don't understand the message, please ask for help. You can, if
necessary, ask the computer for help, by typing HELP followed by the
number in the error message. E.g. if the message started:
 	ERROR 12
.br
then type:
 	: HELP 12
.br
followed by the <carriage return> or <line-feed> button.
.in -5

Notice that when you type in the function definition, the computer does not
obey the print instructions given by the print-arrows. It remembers them for
future use. To get the instructions in the function obeyed, do the following:
 	: HI();
.br
This says "please carry out the instructions specified in the definition of
the function called HI".
The parentheses mean "obey the function". Later you'll see that it is sometimes necessary
to put something between the parentheses.
.br
If you do the following, it will not
obey the function, but merely print its name out:
 	: HI=>

Try HI(); several times. The computer always executes the instructions,
unless you leave out a semi-colon, or one of the parentheses. Try that too!
.br
Try the following:
 	: REPEAT 3 TIMES HI() CLOSE;
 	: REPEAT 4 TIMES HI() CLOSE;
.br
The moral is: wherever possible let the computer do your repetitive work
for you! Try the following, and interrupt with CTRL and X when you've had
enough:
 	: REPEAT 99 TIMES HI() CLOSE;

By now it is quite likely that you have made typing mistakes and had
"error messages" printed out at you. Don't worry: this happens to
everyone. Try to understand the message, but if some bits are incomprehensible,
then ask for help, or use the HELP command mentioned above.

If things go mysteriously wrong and you are not getting any response from the computer,
perhaps because you've left out a closing bracket "]", then you can always force a
"setpop" by typing CTRL and X (i.e. hold down the CTRL key and type X). Try it.
Your function HI should still work after that. Try it.

Now try a version of the function which prints out your name. Type
the following, with your name in place of the dots.

.ne 4
 	: FUNCTION HI();
 	:	[HI THERE ...] =>
 	:	[HOW ARE YOU?] =>
 	: END;
.br

Now test the function as before, by typing : HI();

.mh9
Giving a function a formal parameter
------------------------------------
.hm
Suppose you want to define a function which behaves slightly differently
at different times. For instance, you may want a function which will
greet somebody, but not always the same person. E.g. if the function
is called GREET, then typing GREET([FRED]); should make it greet Fred,
whereas typing GREET([JEMIMA]); should make it greet Jemima.

To define such a function, you need to be able to join two lists together.
In POP11 the operation "<>" allows you do do this. Try the following:
.ne 3
 	: [HI THERE] <> [JEMIMA] =>
 	: [HI THERE] <> [FRED] =>
 	: [HOW ARE YOU] <> [WILLY] <> [?]  =>
.ne 2
 	: [WILLY] -> NAME;
 	: NAME =>
.br
The last two commands said, respectively, "assign the list [WILLY] to be
the value of the variable NAME", and "print out the value of the variable NAME".
Notice that since NAME is not a function which we are trying to
execute, but merely a thing which has a value to be accessed, we don't
type "NAME()\ =>". I.e, the parentheses are not required. Try
typing that. You'll get an error message.
.br
Since NAME now has a list as its value, you can do the following:
 	: [HOW ARE YOU] <> NAME <> [?]  =>

Try the following and notice the difference it makes whether you use the list
brackets or not:
.ne 4
 	: NAME =>
 	: [NAME] =>
 	: [HELLO] <> NAME =>
 	: [HELLO] <> [NAME] =>

You can give the variable NAME a new value (which is why it
is called a variable). Try:
 	: [FATHER CHRISTMAS] -> NAME;
 	: NAME =>
 	: [HI THERE] <> NAME =>
.br
Try your own variations, including assigning differnt values to the variable NAME and
using different variables, e.g. N, NAME1, NAME2, L, LIST, etc.

You can now define the function GREET as follows:

.ne 4
 	: FUNCTION GREET (NAME);
 	:	[HI THERE] <> NAME =>
 	:	[HOW ARE YOU?] =>
 	: END;

This says that when you ask the computer to run or execute the function
GREET you are going to give it an "argument" or a "parameter", represented
by the variable NAME. The first print instruction says, make a list by
joining the list [HI THERE] to the list represented by NAME and print out
the result. Try executing (or "calling") the function with several different arguments:
.ne 3
 	: GREET([FRED]);
 	: GREET([ME]);
 	: GREET([THE MAN ON THE MOON]);

Try other variants.
.br
Try redefining GREET so that it inserts the name before the question mark
in its response.

.mh9
Repetition
----------
.hm
Instead of typing in all those GREET commands separately, you can
define a function, e.g. called MULTIGREET, to execute GREET
several times over, with specified names.
You need to be able to create a list of names suitable for GREET
to work on. Here is such a list. Try typing:
 	: [ [TOM] [DICK] [HARRY] ] =>
.br

This is a three element list.
.br
There are two functions in POP11 which the system already knows
about, which are useful for manipulating lists, and you can use them
in defining MULTIGREET, namely the functions HD and TL.
The POP11 function HD (i.e. head) can be used to produce the first element of a
given list. E.g. try:
 	: HD([ [TOM] [DICK] [HARRY] ]) =>
.br
The spaces between the brackets are not essential. They've been put in to help
you read the line more easily.
.br
(If there's no print out, you've probably missed a closing bracket, so try
CTRL and X to interrupt, and restart.)
.br
Similarly the function TL (i.e. tail) gets hold of everything in the list
except the first element. Try this:
 	: TL([ [TOM] [DICK] [HARRY] ]) =>
.br
Instead of typing that list every time you could assign it to some
variable, thus:
.ne 4
 	: [ [TOM] [DICK] [HARRY] ] -> L;
 	: L =>
 	: HD(L) =>
 	: TL(L) =>
.br

To apply GREET to the first element of L type:
 	: GREET(HD(L));
.br
Now to work on the rest of the list alter L so that it refers to the
tail, i.e. assign the TL of L to L, thus:
.ne 2
 	: TL(L) ->L;
 	: L =>
.br
So you can GREET the next person:
 	: GREET(HD(L));
.br
Try assigning the TL of L to L again, and applying GREET to the HD.

We now have the basic tools for defining MULTIGREET. The
idea is simple. MULTIGREET is a function of one parameter,
represented by a variable L, say. It works by applying GREET to
the HD of L, and then restarting, i.e. applying itself, to the
rest of L, i.e. to TL(L). Notice that if you've already defined a function
e.g. GREET, then you can use it just like a system function, e.g. HD or <>,
in defining additional functions.
.br
So:
.ne 4
 	: FUNCTION MULTIGREET (L);
 	:	GREET(HD(L));
 	:	MULTIGREET(TL(L));
 	: END;
.br

Try it:
 	: MULTIGREET([ [TOM] [DICK] [HARRY] ]);
.br

Everything is fine, until GREET has been applied
to all the elements in the list. After that MULTIGREET tries to
continue with the empty list []. You can see what's going on if you ask
the computer to "trace" the two functions. Try this:
 	: TRACE GREET MULTIGREET;
.br

That says, alter the functions so that when they are about to start
they print out a message (e.g. " > GREET ") and when they've finished
they print out a message, (e.g. " < GREET ").
Try this:
 	: GREET([FRED]);

So in "trace printing", ">" means "starting", or "entering", and "<" means
"finished" or "leaving".

Now try MULTIGREET with the tracing on:
 	: MULTIGREET([ [TOM] [DICK] [HARRY] ]);

You'll see that disaster strikes when MULTIGREET is about to
be applied to [], the empty list.

How can you prevent this? The answer is, insert a test in the definition
of MULTIGREET to see whether the list is []. If so, it should
perhaps print out a final comment, e.g. "nice to meet you all", and then
NOT restart. But if the list is not equal to [], then it should do as before. So:

.ne 8
 	: FUNCTION MULTIGREET (L);
 	: 	IF	L = []
 	:	THEN	[NICE TO MEET YOU ALL] =>
 	:	ELSE
 	:		GREET(HD(L));
 	:		MULTIGREET(TL(L));
 	:	CLOSE
 	: END;
.br

This uses a frequently occurring construction, which can be represented as:
 IF <condition> THEN <action1> ELSE <action2> CLOSE
.br
where the CLOSE is needed to specify the end of the action. If the <condition> produces the result TRUE
then the first action is exectuted. If it produces the
result FALSE then the second action is executed. Later
you'll meet other forms of conditional statement.
.br
Using this we have
given the function MULTIGREET a new definition (overwriting
the old one), in which there is a "stopping test" and a "stopping action",
in addition to the "main action" and the "restarting" (or "recursive")
action.
.br
Try it:
 	: MULTIGREET([ [TOM] [DICK] [HARRY] ]);
.br
and with tracing:
.ne 6
 	: TRACE MULTIGREET;
 	: MULTIGREET([ [TOM] [DICK] [HARRY] ]);
 	: UNTRACE GREET;
 	: MULTIGREET([ [YOU] [ME] [EVERYONE] ]);
 	: UNTRACE MULTIGREET;
 	: MULTIGREET([ [FRED] [WILLY] [ROVER] [JEMIMA] ]);
.br

Notice that UNTRACE stops the tracing of a particular function.
Try some more variants.
.mh9
Using READLINE
--------------
.hm

For some purposes it is inconvenient to have to specify a parameter when
you "call" or "execute" a function. You can leave it to the function to
ask for the information it needs, then read in your answer. In this way
you begin to define a conversational program. Try this:

.ne6
 	: FUNCTION HELLO();
 	:	VARS NAME;
 	:	[HELLO WHO ARE YOU?] =>
 	:	READLINE() -> NAME;
 	:	[NICE TO MEET YOU] <> NAME  =>
 	: END;
.br

The second line of this says that the function needs a "local variable"
called NAME which is to be used for holding information for this function.
When you ask the computer to execute this function, it will print out a line,
then wait for you to type in a line, which will then be read in by the
instruction READLINE.
Try it:
 	: HELLO();
.br

Don't forget to terminate your response with the CR or "return" button. You
shouldn't type the list brackets "[" and "]" when you tell the computer your name:
they will be taken for granted by the function READLINE.
Try HELLO(); several times, with different names.

Can you alter HELLO so that before it finished it prints out something
like: [PLEASE TALK TO ME SOME MORE ....], with the name in place
of the dots?

Try the following:
 	: REPEAT 4 TIMES HELLO() CLOSE;
.br
Try redefining HELLO so that it calls itself at the end. That is, insert
 	:	HELLO();
.br
before END. What will happen if you then type HELLO(); ? Try it. You'll
eventually have to type CTRL and X to interrupt, since there is no
condition in the function to terminate the "infinite" recursion.
.mh9
CREATING AND EDITING FILES
==== == === ======
.hm
.sp 2
By now you will be quite fed up with having to retype things frequently.
You don't have to!
You can ask to computer to store things for you on its magnetic discs as
you type them in. Then you can ask the POP11 system to read in your
commands from the disc.
If POP11 finds errors it will tell you, and you can then alter your
program by changing the faulty line or lines, and start again, without
retyping the whole thing.
So take a break from this demo and spend a little time learning to use the editor.

Actually there are two editors, one called ED and one called EDIT. The
latter is more restricted, but easier to learn to use. So ask for the
"demo" on EZYPOP, which tells you about it.
If you have used an "on-line" editor previously, then you may prefer to
learn about ED instead. In that case ask for the demo called "LITTLED", which
is an introduction to a basic subset of ED.
.mh9
CONCLUDING REMARKS
========== =======
.hm

To gain maximum benefit from your experience, you are advised to tear
off the sheet of paper you've produced, and go through it carefully, trying to make
sure you understand everything that happened, or at least most of it!.
It is also a good idea to try to write out in English an account of what
you have done.

As an exercise in methodology, consider whether you have any hope of finding out
how the system works by doing experiments on it. Can you perhaps find out how
it is able to understand and obey POP11 commands? Is this any different from the
task of a psychologist or linguist, trying to understand how people work?


N.B.  TO LOG OUT:  TYPE  ^D  that is, hold down CTRL key(on left) and
type D.
.sp 3
.tp 10
IF YOU HAVE ANY COMMENTS, SUGGESTIONS, CRITICISMS, etc., PLEASE LET
US KNOW. ONE WAY IS TO USE THE "MAIL" FACILITY ON THE COMPUTER, AS FOLLOWS:

.nf
Type %MAIL AARON
then CR (i.e. "return").
Then type all your comments.
Then type CR
Then type ^D  (i.e. CTRL and D simultaneously), to indicate you've finished.
.br
(Instead of AARON, you can type STEVE.)
.fi

You are strongly advised to learn to use the editing facilites described in
EZYPOP (see above). This will save you an enormous amont of time.

There are many more handouts ("demos") which you can ask for.
INTRO2 gives lots of things you can try out using lists and elementary arithmetic.
.br
INTRO1 includes a program to print out the words of the song OLD MACDONALD.
.br
LIST1 and LISTS2 have several more exercises on building and manipulating lists.
.br
SILLYSENT shows you how to get the computer to generate lots of silly sentences,
whereas ELIZA and CONVERSE are about designing programs which will
begin to resemble conversationalists.
.br
TURTLE is concerned with getting the computer to draw pictures which can be
printed out on a teletype.
.br
NUMBERS and ARITH0 and ARITH1 are about getting the computer to simulate some of
the counting and adding behaviour of a young child.
.br
There are lots more demos. For a complete list ask for the INDEX.
There is also a list of possible PROJECTS to help you if you can't think of
something you particularly want to do.
