.fo 'Aaron Sloman''2 June 1977'
.he 'TURTLE'- % -'Starting POP11'

.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.



.ce 2
GETTING TO KNOW THE POP11 TURTLE PACKAGE
------- -- ---- --- ----- ------ -------

By playing with the "turtle package" you can (a) have an amusing
time, (b)\ begin to learn the syntax of POP11 commands, function
definitions, etc. You will also learn how the computer complains when
you make mistakes.

Before reading on and playing with the turtle, you may find it worth-while to
glance at the final section of this demo, headed "CONCLUDING REMARKS".

The turtle package
is a collection of functions added to POP11 which enable you to use
a teletype to draw pictures. The picture is actually constructed inside
the computer, in an array called PICTURE, and you can get it printed out
on the teletype by typing DISPLAY();

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
.in -5
.fi

Here is what you can do to use the turtle package.

Log in and when the POP11 system has greeted you, type

 	TURTLE();

There will be a pause, followed by a little message when the turtle
is ready.
This takes some time because the POP11 system has to read in lots of
program definitions from the disc, where they are stored.
When the computer types a colon at you thus:

:

it means the POP11 system is ready, waiting for you to type something
in.

The turtle is now ready to draw things for you.


Initially, you are provided with a (small) blank picture, so if
you type:

 	DISPLAY();

you'll get a blank picture printed out. Try it.
The numbers printed alongside the picture are to help you count along and
up. The "T" tells you where the "turtle", is, the imaginary creature which
crawls around the picture leaving a trail of marks. You are also given information
about its current position, and the "heading" i.e. the direction in which
it is facing. This is the direction in which it will draw a line, when
you give the draw command.

The pictures are drawn by an imaginary "turtle" which you can command to crawl
around the picture, leaving a trail of marks (e.g. asterisks).
The numbers that are printed alongside the picture are to help you locate
positions in the picture - the bottom left picture location corresponds to
X=1 and Y=1. A "T" appears in the picture to indicate where the turtle
is, waiting to draw or jump, etc. Further information about the turtle
is printed below the picture, specifying the position and the
"heading", i.e. the direction the turtle is facing, represented as the angle the direction makes with the horizontal to the right.
So when the turtle is facing to your right, the heading is 0.

The initial location is not (1,1), but (1.50, 1.50), where the ".50"
indicates that it is in the middle of the square.

Type:

 	JUMPTO(1,1);
 	DRAW(5);
 	DISPLAY();

The JUMPTO command put the turtle in the bottom left hand corner of the picture.
It starts off facing to the
right (your right, or "East"). The DRAW command told it to move a distance of five units,
leaving a trail.
More precisely, it said "execute the function DRAW with 5 as argument".
Similarly, "DISPLAY()" means: "execute the function DISPLAY, with no
argument". The semi-colon ";" is just a separator, indicating
where an instruction ends.
Type:

 	[% XPOSITION, YPOSITION %] =>

This should print out two numbers telling you the co-ordinates of the square where the turtle is where the turtle is.

More precisely, it will print out a "list" containing the two numbers.
The brackets "[%" and "%]", called "decorated list brackets",
tell POP11 to make a list of the values of the things between the
brackets. The list will be printed out with "undecorated" brackets,
namely "[" and "]".

The print-arrow "=>" is used several times below. It means, roughly,
"print out all the results so far, on a new line, with two asterisks".
 
Later, you'll learn how to use lists to build up sentences and
other "data-structures" which the computer can analyse and re-arrange.

When there's only one thing to be printed out, you need not
bother making a list. So you can find the turtle's heading, by typing:
 	HEADING =>
.br
This prints out the value of the variable HEADING, namely a number
representing the angle through which the turtle has turned from
the horizontal.



The picture initially provided is ten units wide and ten units high.
If you try to draw beyond the edge of the picture, you'll get an error message.
Try the following sequence:

 	TURTLE();		comment: start new picture;
 	DRAW(99);		comment: try drawing a long line;

This will generate the error message. You can now use DISPLAY, as before
to see how far the turtle got before leaving the picture:

 	DISPLAY();
.br
Then:
 	[% XPOSITION, YPOSITION  %] =>
To get the turtle back onto the picture, type:
 	JUMP(-1);

You'll learn later on how to get a bigger blank picture, if you want one.
You can now do some more drawing:

.tp 2
 	TURN(90); DRAW(5); DISPLAY();
 	[% XPOSITION, YPOSITION %] =>

.in +4
.ll -4
NOTE: If things get in a mess and you want to start again, then
.br
(a) Hold down the button marked "CTRL" and type X. This will
reset the POP11 system, and make it print SETPOP.
.br
(b) Type TURTLE();  This will create a blank picture
with the turtle in the bottom left hand corner facing to the
right. The picture has size ten by ten. If you do this you'll
need to retype appropriate DRAW and TURN commands to get
your picture to the required state.
.in -4
.ll +4

Now do:

 	TURTLE();
 	DRAW(5);
 	TURN(90);
 	DRAW(5);
 	DISPLAY();
 	[% XPOSITION, YPOSITION, HEADING %] =>

The TURN command said to the turtle: "turn left (counterclockwise)
by 90 degrees".  So having previously been facing to the right, it is 
now facing up. The variable HEADING has as its value a number
representing the angle between the turtle's current heading and the
"X-axis", measured in degrees.
Try:

 	TURN(90);
 	HEADING =>
 	TURN(-90);
 	HEADING =>
 	[% XPOSITION, YPOSITION %] =>

The TURN command does not affect the position, only the heading.
TURN applied to a negative number (e.g. -90 ) means "turn clockwise".

Now make the turtle move back towards its original position:

.tp 5
 	TURN(135);
 	DRAW(6);
 	DISPLAY();
 	[% XPOSITION, YPOSITION, HEADING %] =>
.sp 4
.tp 10
.ce 2
DEFINING A FUNCTION
======== = ========

You may get tired of typing XPOSITION, YPOSITION, HEADING => every time you
want the turtle to print out its current state. So you can define a
function called WHERE which will do it all for you.
Type:

.tp 5
 	FUNCTION WHERE;
 	  [% XPOSITION, YPOSITION, HEADING %] =>
 	END;

You can execute the function just defined, by typing:
 	WHERE();

Notice the difference between defining the function, i.e. telling the computer
what WHERE is to mean, and "calling" or executing the function, i.e. asking
the computer to do it.

You could make the function print out something a bit more meaningful than
just a list of three numbers. You'd probably prefer it to say what the
numbers are. Try redefining it along the following lines:

.tp 8
 	FUNCTION WHERE;
 	  [% 'X AND Y CO-ORDINATES ', XPOSITION, YPOSITION %] =>
 	  [% 'HEADING OF TURTLE ', HEADING %] =>
 	END;

Then execute this by typing:
 	WHERE();

The old definition of WHERE will have been forgotten, as a result of your
giving a new definition. (In technical jargon: the old version has been
"garbage collected" by the POP11 system!)

In the second definition of WHERE we put some words in "string quotes"
 	' ......... '
.br
These quotes tell the computer to regard the characters in between as
forming a string of characters to be treated as an object, not a sequence of
instructions to be obeyed.

Notice that a function definition always starts with the word FUNCTION
(followed by the name of the function being defined), and always ends with the
"closing bracket", END.

It is a good idea to "indent" the bits between "FUNCTION" and "END",
by typing a space or two at the beginning of the line. This helps to
bring out more clearly the structure of your definition, especially
when you get around to designing more elaborate functions.

.tp 8
.ce 2
BIGGER PICTURES
====== ========

If you want to start on a new picture, perhaps bigger than the original one
type:

 	NEWPICTURE(20,16);

This will produce a new blank picture 20 spaces wide and 16 high.
Type:

 	WHERE();

NEWPICTURE always restarts the turtle in the bottom left corner facing right.

Try drawing a rectangle, say 10 units wide and 15 high, then display it.

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.

.sp 3
.tp 10
.ce 2
CREATING AND EDITING FILES
==== == === ======
.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 you should now have a break from the turtle 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.

If you are quite happy typing things straight into the
computer, you need not, for the present, bother with the editor.
However, you'll find it essential later on.

.sp3
.tp 10
.ce 2
BACK TO THE TURTLE
==== == === ======

You may wish to make the turtle leave a different sort of trail when
it draws. You can do this by changing the "paint". E.g. if you wish
to make it leave a trail of dots instead of asterisks do:

 	"." -> PAINT;

i.e. assign the word "." to be the value of the variable PAINT.
Try it then draw something and display the picture.

Now clear the picture (e.g. NEWPICTURE(15,15);) and try to
draw a square of side ten units long (using whatever paint you like).
You could try typing something like:

 	DRAW(10);  TURN(90);

four times. (Commands don't have to occur on separate lines.)
Try it then display the picture. Instead of typing the same thing four times,
you can use a REAPEAT instruction, e.g.:

.tp 4
 	REPEAT 4 TIMES
 	  DRAW(10);
 	  TURN(90);
 	CLOSE;

Give the turtle a new paint (e.g. "+" ), then try the above, then display the
picture. Then try:

 	REPEAT 4 TIMES DRAW(5); TURN(90); CLOSE;

Then display the picture again. If you don't understand what has happened,
ask for help. One thing we cannot do anything about is the fact that
the teletypes make squares look like rectangles because they type with
bigger spaces between rows than between characters in the
same row.

It is a bit tiresome having to type in the whole REPEAT instruction every
time you want to draw a square.  To avoid doing so,  you can define a new
function called SQUARE, thus:

.tp 4
 	FUNCTION SQUARE(SIZE);
 	  REPEAT 4 TIMES
 	    DRAW(SIZE); TURN(90);
 	  CLOSE;
 	END;

This tells the computer to store a function called SQUARE which
is to be executed with an argument, temporarily named SIZE, and which, when
executed will draw and turn four times, the distance drawn depending on the
value of SIZE. Type in this function definition, make a new picture
about 20 by 20, then use the function SQUARE to draw a few squares,
thus:

.tp 7
 	SQUARE(15);
 	WHERE();
 	DISPLAY();
 	SQUARE(10);
 	WHERE();
 	SQUARE(5);
 	DISPLAY();

Notice that in the definition of the function SQUARE the word CLOSE
occurs as a "closing bracket" for REPEAT, and END as a closing bracket
for FUNCTION, just as ")" is a closing bracket for "(", and "]" is for "]".

Notice also that SQUARE(15); means, roughly "execute the instructions
specified within the definition of function SQUARE, with 15 as the value
for the variable SIZE".

Now try this:

.tp 7
 	NEWPICTURE(20,20);
 	1 ->PAINT;	comment: prepare to leave a trail of 1s.
 	JUMPTO(6,6);
 	SQUARE(8);
 	DISPLAY();
 	WHERE();

.tp 3
 	2 ->PAINT;
 	JUMPTO(2,2); SQUARE(16);
 	WHERE(); DISPLAY();

.tp 4
 	JUMPTO(10,4);
 	3 -> PAINT;
 	TURN(45); SQUARE(8);
 	DISPLAY(); WHERE();

Notice that JUMPTO, unlike DRAW, requires two arguments, i.e. two numbers
representing the XPOSITION and the YPOSITION of the location to which you
want the turtle to move. It does not alter the value of HEADING.

What would it have been like trying to draw a picture like that without being
able to define a function, and without having a REPEAT instruction?
.sp 3
.tp 10
.ce 2
USING DRAWTO
===== ======

How could you draw a line across one of the squares from one corner to another?
You could try to TURN(45); then call DRAW. But you'd have to calculate
the distance. Instead, if you know that the turtle is already at one of the
corners, and you know where the other corner is, i.e. you know its co-ordinates,
then you can use the function DRAWTO. For instance, if you want to draw a 
line to location (15,15), i.e. fifteen along and fifteen up, then type:

 	DRAWTO(15,15); DISPLAY();

.tp 6
Try the following, with a new picture:

 	DRAWTO(15,1); DRAWTO(15,15);
 	DRAWTO(5,15); DRAWTO(5,5);
 	DRAWTO(10,5); DRAWTO(10,10);
 	DISPLAY();

If you like, change the paint between instructions. E.g. start by using
"A" as paint, then "B", then "C", etc.

Instead of giving all those DRAWTO commands to draw the "squiral" (i.e.
"square spiral" you can use a REPEAT instruction. You need to define
a variable, say DIST, which will represent the amount to be drawn each
time. Give it a starting value before the repeat instruction, then alter
it each time after drawing, inside the REPEAT instruction.
So make a new picture (e.g. 20 by 20) then:

.tp 11
 	VARS DIST;		comment: declare the variable DIST;
 	15 -> DIST;		comment: assign 15 to be its value;

 	REPEAT 4 TIMES
 	  DRAW(DIST); TURN(90);
 	  DRAW(DIST); TURN(90);
 	  DIST - 5  -> DIST;
 	CLOSE;

 	DISPLAY();
 	WHERE();

The line before CLOSE says: subtract 5 from DIST and assign the result to be
the new value of DIST. The whole REPEAT instruction, which starts  with
REPEAT and ends with CLOSE (which is why we recommend indenting the middle bit),
says "do everything between TIMES and CLOSE four times".

If you now want to draw a different squiral it will be rather tedious to
have to retype all that. Could you define a function to do it? Perhaps you'd
like to vary the initial value of DIST and the number of repetitions.
That is, instead of the number 4, have a variable called NUM. You could
also allow the amount subtracted from DIST to be a variable,
instead of simply being 5 every time. So try something like this:

.tp 7
 	FUNCTION SQUIRAL(NUM, DIST, SUB);
 	  REPEAT NUM TIMES
 	    DRAW(DIST);
 	    TURN(90);
 	    DIST - SUB  -> DIST;
 	  CLOSE;
 	END;

Try using the ED command to store this definition.
This defines a function called SQUIRAL which will have to be given
three arguments, to be called NUM DIST and SUB, when it is
executed. Create a new picture and try executing it thus:

.tp 2
 	SQUIRAL(15, 17, 1);
 	DISPLAY();

This says, run SQUIRAL with 15 as the value for NUM, 17 as the value
for DIST and 1 as the value for SUB, the amount to be subtracted each time.

Try running SQUIRAL with different values, e.g.

 	SQUIRAL(12,20,1);

You could redefine SQUIRAL so that the DISPLAY command is
included between CLOSE and END.
You could also redefine it so that before the REPEAT command, it
assigns 1 to PAINT, then before the CLOSE it adds 1 to paint, i.e.
 	PAINT + 1  -> PAINT;

This would make it use a different paint for each arm of the squiral.

What will the following do:
 	SQUIRAL(5,5,2);

Notice that if you subtract 2 from 5 more than twice you end up with
a negative number. So DIST will become negative. That's alright:
drawing a negative amount just means drawing backwards. Similarly,
JUMP(-3); means "jump 3 backwards".
.sp3
.tp10
.ce 2
USING TURNTO
============

Try the following:
 	: NEWPICTURE(10,10);
 	: JUMPTO(2,2);
 	: DRAWTO(6,6);
 	: DRAW(3); DISPLAY();
.br
Notice that the DRAWTO command drew a line, but did not make the turtle
face along that line. So the DRAW command used the original heading.
The function TURNTO is available to make the turtle face in the direction
of a specified point. TURNTO(X,Y) makes it face in the direction of
the point with co-ordinates X,Y.
.br
Try the following, or some variation of it:
.ne 6
 	: NEWPICTURE(21,21);
 	: JUMPTO(11,11); TURNTO(21,1); DRAW(5);
 	: JUMPTO(11,11); TURNTO(11,1); DRAW(5);
 	: JUMPTO(11,11); TURNTO(21,1); DRAW(5);
 	: JUMPTO(11,11); TURNTO(21,21); DRAW(5);

You can't make the turtle TURNTO the point its already on. Try:
 	: JUMPTO(1,1); TURNTO(1,1);
.br
Could you define a function called SPOKES, which takes a pair of
coordinates and a list of pairs of co-ordinates, makes the turtle
jump to the point defined by the first pair, then turn towards each of
the other points in turn and draw a line towards it. So the above
sequence of commands could be replaced by:
 	: SPOKES(11,11, [[21 21] [11 1] [21 1] [21 21]]);
.br
If you've not yet done anything with lists ignore that.
.sp 3
.tp 10
.ce 2
USING JUMPBY
===== ======
.sp 1
See if you can guess what the following will do, then try it:

.tp 8
 	NEWPICTURE(30,25);
 	1 -> PAINT;
 	REPEAT 5 TIMES
 	  DRAW(3);
 	  JUMPBY(2,2);
 	  PAINT + 1  -> PAINT;
 	CLOSE;
 	DISPLAY();

The only new idea is JUMPBY.  JUMPBY(X,Y) means, "without leaving a
trail move X units to the right and Y units up". To move to the left, or down,
you can use negative numbers.

Try the last lot again using DRAWBY instead of JUMPBY. The only difference is
that DRAWBY leaves a trail.  Both require two arguments, like DRAWTO and JUMPTO,
but the arguments are not taken to be co-ordinates of a point.

Can you anticipate what the following will do:

.tp 5
 	NEWPICTURE(25,15);
 	"*"  -> PAINT;
 	JUMPTO(1,3);
 	TURN(45);
 	REPEAT 5 TIMES DRAW(5); TURN(-90); DRAW(5); TURN(90); CLOSE;

Display the picture and use WHERE.
Try again, replacing the 5 in the second DRAW command with 4.

If you've had funny error messages involving incomprehensible things
like  {0 0 0 * 0 0 0 * 0 0 ***} then you may like to know that this
is the computer's attempt to print out a fragment of the "data-structure"
which stores information about the picture.
.sp 3
.tp 10
.ce 2
EXAMINING THE PICTURE
========= === =======
.sp 1
The picture inside the machine
is really an object called an array. The array has a name PICTURE. You can
therefore examine its contents. For instance to find out what is at
location (1,3) type:
 	PICTURE(1,3)  =>

If that location is a blank it will have a 0, otherwise whatever paint
the turtle left there.  You can look at several locations, thus:
 	[% PICTURE(1,3), PICTURE(1,4), PICTURE(2,4)  %] =>

If you want to know what is at the current turtle location type:
 	PICTURE(XPOSITION,YPOSITION) =>

This is a bit much to have to type each time, so you can define a function called
COLHERE thus:
.tp 3
 	FUNCTION COLHERE;
 	  PICTURE(XPOSITION, YPOSITION)  =>
 	END;

so:

.tp 6
 	JUMPTO(1,5);  0  -> HEADING;
 	REPEAT 7 TIMES
 	  COLHERE();
 	  JUMP(1);
 	CLOSE;
 	=>

should print out what is at 7 locations in a straight line starting at
(1,5) and going to the right.

Using functions like COLHERE you can make the turtle move about the
picture examining its contents and perhaps trying to recognise or interpret
what has been drawn. What would it require in order to be able to
recognise squares, as well as draw them?
.sp 3
.tp 10
.ce 2
SUMMARY OF TURTLE COMMANDS
======= == ====== ========
.sp 1
Here's a reminder of the main turtle functions, in case you want to
play some more:
.in +13
.ti-10
JUMP  DRAW	both take a number, positive or negative, as argument.
.ti-10
NEWPICTURE	takes two arguments, the width and height required.
.ti-10
JUMPTO  DRAWTO	both take two arguments, representing a location.
.ti-10
JUMPBY DRAWBY	both take two arguments, representing amounts
.ti-10
to move along and up.
.ti-10
DISPLAY		prints out the current picture.
.ti-10
TURN	takes a number (positive or negative) indicating how many degrees the
turtle should turn: clockwise if the number is positive, anti-clockwise otherwise.
E.g. TURN(90) alters the heading for the next DRAW or JUMP
command as if the turtle had turned left 90 degrees.
.ti-10
TURNTO		takes two numbers and makes the turtle change its heading.
E.g. TURNTO(10,15); makes the turtle face in the direction of the point with
co-ordinates 10 and 15. So DRAW(5); will then move it to that point.

The variables XPOSITION, YPOSITION, HEADING, and PAINT, represent the state of
the turtle.

PICTURE(X,Y)	gives the contents of the picture at location X,Y.
.in -13
.sp 3
.tp 10
.ce 2
CONCLUDING REMARKS
========== =======

You have now learnt enough to be able to draw quite elaborate pictures, if
you wish. Notice that although you've used numbers, most of the information
you've given the computer has been in the form of instructions about what
to do. For instance, the numbers are only a small part of the definitions
of the functions SQUARE and SQUIRAL. Some of the other "crib sheets" will
introduce you to other kinds of objects which the computer can store and
manipulate, e.g. words, lists, strings.

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
the turtle package is, and how it is used.

Here's a final question: suppose you were a Martian anthropologist and had
just met and played with our computer, not knowing that it had been
programmed by people. You might think it was just another, rather restricted
kind of person, or animal, with whom other people could communicate in
rather restricted ways.  Now, being a scientist, you'd want to understand
how it works. Can you think of experiments or measurements or anything else
you could do to find out how it works? E.g. How does it draw squares?

What sort of thing would an answer look like? Is the function SQUARE which
you typed in an explanation of how it draws squares?  Is there any way you
could tell whether it was the correct explanation?

 E.g. suppose the definition
actually used had had TURN(-90) instead of TURN(90) - could this be detected
by some kind of observation or experiment?  Or suppose the TURN command had
come before the DRAW command in the definition?

Would being able to look inside the computer help much?

The full explanation of how the computer manages to understand and execute
your function definitions would have to include a detailed description of the
programs Steve wrote which defined the POP11 system. Could programs be part of
the explanation of how people understand English, or how they see things, or
part of the explanation of how social systems work, or how decisions are
taken, or how beliefs spread or change?

These are very hard questions. Simple answers cannot be expected.


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:

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