LOGO Commands, Part 2

Note: In addition to commands illustrated here, other commands are listed and explained under the "Help" menu in the MicroWorlds program. On the "Help" menu, drag down to "Vocabulary." This will provide a list of all LOGO commands. Click on any one of the commands, and you will get an explanation of the command.

Explanations will be in black.

Commands will be in red.

Especially important notes will be in Carolina Blue.

Commands are typed either in the Command Center, or in programming a button or a turtle, or in writing a program.

VI. Writing Programs

LOGO is unique among programming languages in that immediate action can be attained by typing a command in the Command Center and then tapping the return key. This makes LOGO a valuable learning tool for young children because they can see immediately if what occurred on the screen was what they expected. This is a much more effective way to learn from error than by being told, "No. that's wrong." In other programming languages, you have to write a complete program before you can try it to see whether or not you got what you expected. Papert, the developer of LOGO, wanted an arrangement whereby the child would teach the machine rather than the other way around. We know this is a sound learning principle because we all know that you learn by teaching. Pappert worked for five years with Jean Piaget, and so he knew how children cevelop intellectually. This placed Papert in an excellent position to develop a learning system.

Remember the system of making LOGO correspond to the reality of two-dimensional geometry. In keeping with this principle, the monitor screen is considered to be a sheet of paper. This paper has a back side as well as a front side. The back side is where programs are written; the front side is where programs are executed. Here are the steps for writing and executing a program in LOGO:

1. Get to the back side of the sheet by either clicking on the icon for a sheet of paper in the upper right side of the screen, or by holding down the Apple key and tapping on the f (for flip) key.

2. When you flip to the back side of the "sheet," the word "Procedures" appears near the top right of the screen. The LOGO folks refer to a program as a "procedure," which is a good name for it because it means a procedure to be executed by LOGO.

3. As an example, if you would type the command "square" in the Command Center on the front side of the sheet, you would get the error message, "I don't know how to square." This is where Papert's learning theory comes in. The child now tells the computer, "I am going to teach you to draw a square." Obviously, this is to long a message to give to the computer, so Papert shortened the message to "to square."

4. Every LOGO program (or procedure) begins with the word "to." So, once you get to the back side of the "sheet," you will see a blinking cursor at the top of the screen. Type the word "to."

5. After the "to" there must be a space followed by a single word of your own choosing. This word could be anything you want, but you might as well choose something appropriate to the procedure you want LOGO to perform. In our example, since we want LOGO to draw a square, we might as well name the procedure "square."

6. Therefore, you would type to square on the "Procedures" side of the sheet.

7. Tap the return key after you type the name of the procedure.

8. Type the LOGO commands that will cause the turtle to draw a square. You may type each command on a separate line, or you may type more than one command per line.

9. When you finish typing all the commands needed, tap the return key to go to a separate line, and type end and tap the return key again.

10. The procedure is now defined, by either clicking on the icon for a sheet of paper in the upper right side of the screen, or by holding down the Apple key and tapping on the f (for flip) key.

11. To execute the program, type square in the Command Center and then tap the return key. The turtle should then draw a square. If not, you can go back to the flip side and edit the procedure until you get it to do what you had in mind. This what Papert meant by having the learner teach the computer, and this is quite psychologically different from a teacher telling you, "No, you are wrong." The effect on the learner is quite different.

12. Note that you can write as many procedures on the flip side as you wish. Just make sure that each one begins with to followed by a space and then a single word, and that each one has end as its last line.

13. To run a program, flip to the front side of the "sheet" and type the name of the program in the Command Center, and then tap the return key. The name of the program becomes a command which LOGO will obey. (Note: The to is not part of the name of the program. You don't tell a dog "to sit," do you?)

VII. Repeating a Command

In drawing a square 50 turtle steps on a side, you would have to repeat this series of commands four times: fd 50 rt 90. A short way to do this is repeat 4 [fd 50 rt 90]. This command causes the commands enclosed in square brackets to be executed four times.

VIII. Variables

A powerful kind of program would be one which would draw a square of any size you tell it to. The concept needed here is called a variable, because you can vary, or change, the size of the square. A colon followed by a letter or a word is the way LOGO designates a variable. (Note: There must be no space between the colon and the name of the variable.) The following program would caause LOGO to draw a square of any size that you would specify:

to square :side

repeat 4 [fd :side rt 90]

end

To get this program to draw a square 50 turtle steps on each side, type this in the Command Center: square 50. The same program would draw a square with sides the length of whatever number you type in. If you should type square without adding a number, you would get an error message that says, "not enough inputs to square". If you should type square50, you would get an error message that says, "I don't know how to square50". This happens because there has to be a space between the name of the program and the number you type in.

A program can have more than one variable. For example, if you wanted the program to draw regular figures other than squares, you could arrange to vary the number of times you want the command to repeat and you could vary the angle as well as the side. The following program would do this.

to polygon :number :side :angle

repeat :number [fd :side rt :angle]

end

IX. Interaction

These are specific examples of commands needed if you want to write a program that will include interaction with the learner and feedback to the learner.

question [What is 6 x 7?] (This command stops the running of a program until the learner types in an answer and clicks on "OK.")

ifelse answer = 42 [pr [Exactly right!]] [pr [Sorry, but the answer is 42.]] (If the answer typed in by the learner is correct, the computer obeys the command in the first set of brackets, and ignores the second set of brackets. If, on the other hand, the answer is incorrect, the computer ignores the command in the first set of brackets and obeys the commands in the second set of brackets. This is an extremely powerful and useful command.

X. Random Numbers

random 100 causes the computer to pick a number at random from 0 through 99. Note that the number given with the random command will never be the chosen number. If you wanted 100 to be a possibility, you would use the command random 101.

If you would just type the command random 101, the computer would respond with "I don't know what to do with ____." So, you must tell the computer what to do with the random number it chooses for you. Following are some examples:

pr random 25 (Causes a number from 0 through 24 to be chosen, and printed in a text box.)

pr 1 + random 100 (Chooses a number from 0 through 99 , adds 1 to the chosen number,and and then prints the sum in a text box. With this command, you would never get a 0, and you could possibly get 100.)

Make "a random 10 (This is a useful command when you want to store a number or some words in the computer for later use. This sets up a box, like a post office box, in which numbers and words can be stored. If you wanted, for example, to print what is stored in the box, use the command pr :a Note that the quotation mark names the box, and the colon refers to what is in the box. This is just like a letter in a post office box.)

XI. Calculations

pr 9 + 6 (This command prints 15 in a text box.) (Note: In this version of LOGO, there must be a space before and a space after the operation sign.)

pr 9 - 6 (This command prints 3 in a text box.)

pr 9 * 6 (This command prints 54 in a text box.)

pr 9 / 6 (This command prints 1.5 in a text box.)

Computation can also be performed with the insert and the show commands.