- procedures


Logo commands (or primitives) control a 'turtle' on the graphics screen. It can move forward or back any number of steps, drawing a line as it goes. It can also turn left or right any number of degrees. Commands are entered into the command line and are executed (run) by pressing the keyboard <Enter> key. The Text section below the graphics screen shows all previous commands. You can click on any entry to recall it back into the command line.

Type Forward 80 and press <Enter> to move the turtle forward 80 pixels. Typing Back 40 will move backward 40 pixels.
Type Right 90 to turn 90 degrees clockwise. Move forward again (say Forward 60) to draw a horizontal line.
Have a go yourself.
You can also copy and paste one line codes directly into the command line. Remember, press <Enter> to run.

By putting commands together in procedures, more complex graphics can be drawn. Programs on this site are made up of a number of separate procedures. They can be listed in any order. Procedures are the basis of logo programs. Each procedure is a self contained list of instructions which carry out a particular task.

Procedures can be copied and pasted into the XLogo editor (see how to). They can then be edited if necessary. Closing the window will update the procedure.

Every procedure has a unique name. By using this name, one procedure can call another. A logo program is structured as a list of procedures, called one after the other.

For instance,

To Go
New Dust Star


is a logo procedure called Go which calls three procedures, New Dust and Star in order.
To run the program, just enter Go.

Each procedure can also be called on its own. For instance to run procedure New just enter New.

Some procedures need input data to work on. This is shown after the procedure name.

For instance,

To Plot :X :Y
SetXY :X :Y PenDown Forward 0 PenUp

needs two pieces of data to work, an X value and a Y value. These are placed after the procedure name.

For example, typing in Plot 30 40
will plot a point at position 30 40 in the draw window. By calling the procedure with different input data, different pixels are plotted.

Note that Plot 30
or Plot 30 40 50
will produce an error, as the number of pieces of data is incorrect.

If you need to clear the screen, enter CS or New.

XLogo remembers all procedures that have been entered, and calls upon them as necessary. If a different or modified procedure is entered with the same name as a previous procedure, the old procedure is over written.

As Perlis says, computer programs are "mosaics of interlocking procedures." Procedures can call other procedures, and also themselves. When a procedures calls itself it is called recursive.