Topic 14 - Turtle Words

The Turtle can write on the screen or it can send output to the text window:

SETPC 11 SETPENWIDTH 3
GRAPHICSWRITE "TURTLE

SETPC 10
GRAPHICSWRITE [HELLO WORLD]

 

 

Notice the difference in output and also the need to enclose separate words in square brackets to make a list. The turtle can handle single objects or lists of similar objects. A single object is a list with one member and with no need for enclosing square brackets.

 

 

 

 

 

 

 

 

 

 

You can replace a FD or BK command with GRAPHICSWRITE in any routine:

Let's try something a little more complex. We can use the MAKE primitive to set the contents of a variable:

MAKE "GREETING Hello
MAKE "DAYS [MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY]
PRINT :GREETING REPEAT 7 [PRINT FIRST :DAYS MAKE "DAYS BUTFIRST :DAYS]

CLEARTEXT

We can now define a function which processes a list of the days of the week:

TO WEEK :DAYS IF EMPTY? :DAYS [STOP]
GRAPHICSWRITE FIRST :DAYS
PENUP RT 90 FD 30 RT 90 FD 150 RT 180 PENDOWN
WEEK (BUTFIRST :DAYS)
END

The output here has been scaled using SETZOOM 0.5.

 

 

 

 

 

 

The details of this function are as follows:

  1. The function is called with the parameter DAYS which is a list of the days of the week - you will need to make sure that you set the DAYS variable equal to the full list each time you call the function.
  2. The function stops when the list is empty - the first line checks for the EMPTY? condition.
  3. The second line outputs the first item in the list of days.
  4. The third line moves the turtle down and back to the left, ready to draw the next item.
  5. The fourth line calls the function again with the list as before but minus the first item.
We could reverse the output from list of DAYS by replacing FIRST with LAST and BUTFIRST with BUTLAST.

TO WEEK :DAYS
IF EMPTY? :DAYS [STOP] GRAPHICSWRITE LAST :DAYS
PENUP RT 90 FD 30 RT 90 FD 150 RT 180 PENDOWN
WEEK (BUTLAST :DAYS)
END

 

 

 

 

 

 

We can capture text (and numbers) from the user's keyboard with MAKE and READLIST:

MAKE "NAME READLIST
GRAPHICSWRITE SENTENCE "HELLO :NAME

The GRAPHICSWRITE primitive takes just one value for output so two or more items must be made into a list with the SENTENCE primitive.

We can use these techniques to create all sorts of text processing functions, for example, a simple dictionary: e dictioMAKE "WORDLIST [[TABLE [LA TABLE]] [CARPET [LE TAPIS]] [DOOR [LA PORTE]]]

The techniques you have just seen and used are part of an approach to programming known as 'list processing'. Programming is about data and routines to manipulate them. Logo is derived from the language 'LISP' which was devised in the late 1950s and has been used for writing programs which give computers the power to 'understand' human language language.

LISP and Logo take lists as their data and provide various 'primitive' functions such as 'FIRST', 'LAST' and 'BUTFIRST' to process them. They may not seem so now but these techniques are very powerful and they are still widely used in computer science.


 Return to Logo Home Page