Make your own free website on

Discussion #1 - Program Elements and Commands

As with natural language, the Logo programming language uses letters, numerals, and other symbols such as the quotation mark, the colon, and brackets. In natural language these keyboard characters are used to represent words, numbers, and punctuation marks. In the Logo language they are used to represent program elements. A program element is the basic unit of the Logo programming language. It is represented by a single keyboard character (letter, numeral, or other symbol) or a combination of keyboard characters. As in natural language, a space character or the  <RETURN> key signals the end of a program element.

To be considered a program element, the single character or combination must be meaningful to the Logo Interpreter. The Logo Interpreter is a computer program that translates program elements into the machine language which controls your computer. I find it helpful to imagine that I am carrying on a conversation with the Interpreter - I give the Interpreter instructions in the form of program elements and the Interpreter either carries out my instructions or sends me an "error message" telling me why it cannot do what I wanted. To write a Logo program, you simply type a series of program elements into the command center. Each program element you type means one specific thing to the Interpreter. Unlike natural language, there is never any ambiguity about the meaning of a particular program element (although some elements, such as "random," produce effects which are deliberately ambiguous.)

Logo program elements are divided into three groups:

  1. Procedures are program elements that cause the computer to do something.
  2. Expressions are program elements that provide a procedure with additional information it may require in order to do its thing. The information provided to a procedure by an expression is called an input. Some procedures do not need inputs in order to accomplish their purposes; other procedures need inputs in the form of numbers, words or lists. As you will see in Unit #2, expressions come in five different forms.
  3. Delimiters are the program elements TO and END, that signal the beginning and ending of a defined procedure. Delimiters are explained in Unit #3.

In this book I shall use bold face type for procedures and regular type for expressions as a way of helping you to distinguish between these two groups of program elements. Since the Interpreter doesn't know the difference between bold face and regular type, you should use regular type for both procedures and expressions when you type them in the command center. As you have seen, I shall also use bold face type to call your attention to new technical terms the first time they are used, but I don't think this dual use of bold face will cause you any confusion. The Concept Map in Appendix E may be help you relate these terms to one another.

Many Logo procedures are familiar English words such as forward, left, print, stop, and repeat. Other procedures are two-letter abbreviations for some of these words, such as fd for forward, lt for left, and pr for print. Another group of procedures are combinations of two English words, such as readlist, ifelse, and namepage. (Logo procedures never include a space as one of their characters, since the Interpreter assumes that a space means the end of a program element. The Interpreter has absolutely no common sense or imagination!) Some procedures are abbreviations for two-word phrases such as cg (clear graphics), pu (pen up), seth (set heading), and sqrt (square root).  The fifth and final group of procedures are mathematical symbols, such as +, -, and =. About one hundred Logo procedures are explained and used in this book.

The Macintosh version of LogoWriter includes 252 procedures all together. They are all defined in the pull-down help menu which you may access by clicking on the Apple key at the top left corner of your screen. The Interpreter assumes that everything it reads is a procedure or a delimiter, rather than an expression, unless the program element is a numeral or unless it begins with one of three punctuation symbols. Here are the three symbols that identify program elements as being expressions rather than procedures: a quotation mark (") identifies the expression as a quoted word. There is no "close quotes" to show the end of the word, since the Interpreter knows that a space character signals the end of the program element. a bracket ([) identifies the expression as a quoted list of words. Since spaces are used to separate the words in the list, the Interpreter requires another bracket (]) to signal the end of the list. a colon (:) identifies the expression as a dotted word.

In Exploration #1, you will use procedures that require numerals to provide inputs. Beginning with Exploration #2, you will use procedures that require quoted words, quoted lists, or dotted words to provide inputs. There are two types of procedures: commands and reporters. Commands are procedures that produce effects. Some commands are able to produce effects all by themselves; others require one or more inputs in order to produce their effects. Reporters are procedures that calculate output values. Some reporters are able to calculate an output value all by themselves; others require one or more inputs in order to calculate their values. Since the output value calculated by a reporter is always used as the input to a command, a reporter along with its required inputs (if any) is another form of expression.  You will learn about commands in Exploration #1. Unit #2 explains how reporters are used.

A Logo instruction is a command followed by one or more expressions that provide its inputs. The Interpreter knows which commands work alone and which require inputs. Further, the Interpreter knows how many and what kind of inputs each command needs in order to produce its effect. When the Interpreter translates an instruction into machine language and then produces its effect, we say the interpreter executes the instruction. In order to execute an instruction, the Interpreter first evaluates each expression in order to determine its input value. In Exploration #1 the Interpreter evaluates each numeral by calculating its decimal value, and then passes this number back as an input for the command to use.  In Unit #2 you will learn how the Interpreter evaluates the other four forms of expressions: quoted words, quoted lists, dotted words, and reporters.

You may move the turtle by typing instructions into the command center. The Interpreter executes each instruction as soon as you press the  < RETURN > key. A series of instructions may be typed one after the other on the same line; when you press  < RETURN > the Interpreter executes them in sequence from left to right. Logo instructions may also be used to manage the LogoWriter scrapbook. Instead of selecting options from the pull-down File menu, you may type instructions in the command center. The most commonly used scrapbook commands are explained in the following Exploration section.

Exploration #1 New Commands

Commands are written in bold face type. If the command may be written either as an English word or as an abbreviation, the abbreviation (also in bold face type) is enclosed in parentheses. For your information, two-word phrases that were used to create some of the commands are also enclosed in parentheses. If the command requires the name of a scrapbook page or a number as input, a description of the input (not in parentheses) follows the command or the two-word phrase If this expression is a name, rather than a numeral, it must be typed in the form of a quoted word so that the interpreter will not mistake the input for another command.

Commands that manage the scrapbook:

newpage Saves the page you are working on and turns to a new page.

contents Saves the page you are working on and turns to the Contents page

getpage (gp) Saves the page you are working on and turns to the chosen page.

namepage (np) Gives a name to a new page and enters it on the Contents page.

savepage Saves the page you are working on and returns to the same page.

leavepage Turns to the Contents page without saving the page you are working on.

help colors Turns to the Colors page, which displays all the color numbers. Press  < ESC > to return to the page you are working on.

help help Turns to the Help page, which displays some of the colors and provides other information. Press  < ESC > to return to the page you are working on.

help Turns to a page on which you have written help material to assist the user of your program. Returns to the original page when the user presses  < ESC >.

erpage (erase page) Erases the page you name, removing it permanently from the scrapbook.

printscreen Transfers the text and graphics displayed on the monitor to a printer.

printtext Transfers all the text from the current page, whether or not displayed on the monitor, to a printer.

Commands that prepare the page and the command center

cg (clear graphics) Erases drawings from the page and returns the turtle to her home position.

rg (reset graphics) In addition to the cg effect, resets all the turtle and and background characteristics to their original states.

clean Erases drawings from the page but does not affect the location of the turtle or color of the background.

cc (clear command center) Erases the command center.

setbg (set background) color.number Changes the background color to the one whose number you specify.

Commands that control the turtle

forward (fd) number.of.turtlesteps Moves the turtle in the direction she is heading a distance specified by the number of turtlesteps . Each turtlestep is one pixel on your computer screen.

back (bk) number.of.turtlesteps Moves the turtle in the direction opposite to her heading.

right (rt) number.of.degrees Rotates the turtle to the right through an angle specified by the number of degrees. Each degree is 1/360th of a complete circle.

left (lt) number.of.degrees Rotates the turtle to the left.

home ` Returns the turtle to her home position without erasing the page.

ht (hide turtle) Makes the turtle invisible.

st (show turtle) Makes the turtle reappear.

pu (pen up) Lifts the turtle's pen from the screen so she will not leave a trace as she moves across the page.

pd (pen down) Puts the turtle's pen back down.

pe (pen erase) Erases a previously drawn line as the turtle passes over it.

setc (set color) color.number Changes the turtle's pen to the color specified by the color number.

slowturtle Slows down the turtle for easier tracing of her moves and turns.

fastturtle Returns the turtle to normal speed.

1. Type each of the above instructions, one by one, in the command center. Press  < RETURN > after each instruction to see its effect. If the command requires an input, experiment with different values and observe the changes in effect.

2. Use large numbers as inputs for the fd command. What happens when you run the turtle off the screen?

3. What happens when you use an input larger than 360 for the rt command?

4. Can you draw a square? a triangle? a hexagon? Write an instruction to move the turtle forward to the first corner and then an instruction to turn the turtle right or left the proper number of degrees. Type these two instructions on the same line, and then press  <RETURN> so the turtle will draw the first side and make the first turn. Use the  <UP ARROW> key to move the cursor back up to this line, and press  <RETURN> again to repeat the two instructions without having to type them over again.

5. Try dragging the turtle to a new starting position with the mouse before typing instructions to move her.

6. Teach the turtle to print the word HI in the middle of the page.

7. Can you teach the turtle to print your initials on the page?