When giving instructions to the computer, we must tell it what to do and how to do it. For instance, when we move the turtle FORWARD we must inform it how far forward to move, as in the command FORWARD 25.
The REPEAT command is a more complicated example of this phenomenon. Not only must we tell LOGO how many times to repeat an action, we must tell it what action to repeat:
REPEAT 4 [FD 50 RT 90]Sometimes it is not necessary to give any extra information with a command as in HOME, PENUP, and BYE.
In general, commands to LOGO look like:
procedurename input1 input2 ... inputN
Here, procedurename is the name of the command (e.g. FORWARD or REPEAT) and input1 input2 ... inputN is the information the computer needs in order to execute the command (how far to move forward, how many times to repeat, what to repeat, etc.)
When you first start the program LOGO understands only the most basic commands. It can move the turtle forward, but it does not yet know how to draw a square. However, one benefit of LOGO is that it is an extensible language. You can define new commands or procedures -- just like the old commands, these will consist of instructions for the turtle to follow and may allow you to provide extra information (like how far to turn or move forward.) You can then use these commands in the same way you use commands like FORWARD and RIGHT.
To teach LOGO a new command, use the TO command. Below is an example of the definition and use of the command squiggle0. (The ? and > characters and the line SQUIGGLE0 defined are provided by the computer -- you don't need to type them in.)
? TO SQUIGGLE0 > FD 10 RT 110 FD 10 LT 90 FD 15 RT 10 > END SQUIGGLE0 defined ? SQUIGGLE0 ? REPEAT 12 [SQUIGGLE0]Following the example above, type in your own SQUIGGLE command and run it. Does the squiggle look like you expected it to? If you REPEAT it many times (say 100) what happens? If repeating your squiggle creates a closed circular figure, what is the least number of times you need to repeat it to generate that figure?
Here are three more squiggles; try to guess what they do before you type them in and try them out.
TO SQUIGGLE1 FD 40 RT 170 FD 40 LT 150 END TO SQUIGGLE2 FD 20 RT 90 FD 40 RT 90 FD 20 RT 90 FD 20 RT 90 FD 20 END TO SQUIGGLE3 LT 45 FD 40 RT 90 FD 40 REPEAT 4 [RT 90 FD 10] RT 90 FD 40 RT 90 FD 40 END TO SQUIGGLE4 LT 45 FD 40 RT 90 FD 40 REPEAT 4 [RT 90 FD 10] RT 90 FD 40 RT 90 FD 40 RT 135 ENDYou have now defined five new LOGO commands! For each squiggle, see what happens when you repeat the squiggle. Compare the designs made by these repetitions. How can you tell from the definition of the command whether repeating it will produce a circular pattern or a string of patterns? Some of the designs will be centered on the turtle's starting position and some will lie on a circle that passes through that starting position. What determines whether the pattern is centered on the turtle's starting position?