Topic 14 - Turtle WordsSETPC 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:
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