Table of Contents | Previous Page | Next Page
Copyright Don Sleeth, 1998 ©

Page 3 - Instructions and Procedures

First, start with an Instruction

In the command center type cc and press Enter (stands for clear the command center) and then write the following line:

When the cursor is at the very end, press Enter. Presto! Our first instruction causes the turtle to draw a square.

Let's analyze our one long line of instruction. All the words you see on the line are names of procedures:

pd
- a procedure that puts the current turtle's pen down and requires no inputs and has no outputs

forward
- a procedure that moves the current turtle in the direction its head is pointing by a certain number of steps. The number is a required input.

right
- a procedure that turns the current turtle to the right by a number of degrees. The number is a required input.

The last two procedures require a number as their input. One very important thing to notice is that some procedures require inputs and some don't. This is the glue that holds a Logo instruction together.

Procedure inputs and output

Logo procedures can be thought of as jigsaw puzzle pieces, and our job as programmers is to build puzzles which fit together properly. The procedures that we will build and the built-in procedures that come with MicroWorlds, have a specific number of inputs. It can be zero inputs (such as pd) or one input (such as forward) or more inputs (such as sum). A procedure can also have zero outputs (such as forward)or one output (such as sum). The jigsaw puzzle piece of a procedure with an output has a tab sticking out on the left. When we use procedures in an Instruction we must provide the required inputs and we must provide a place for the outputs to go, in order for the whole instruction to be correct. Think of it as a one line jigsaw puzzle.

Here are two procedures: As you can see, forward has a hole that needs a number input and of course, 50 has a number output that will fit just fine.

Procedures that expect one number as their input will have the right size opening to fit a number (which you can correctly think of as a procedure with no inputs and one output).

The starting edge of a line of Instruction must be solid, that is no output sticking out, and so must the ending edge. Here are some Instructions. Try to guess which ones will work and which ones won't. Type them into the Command Center to test your guess.

Instruction 1

Instruction 2

Instruction 3

Instruction 4

It's really pretty easy to get the inputs and outputs all lined up and in the right order once you pretend the procedures are jigsaw pieces and the instruction must be a completed puzzle! Let's take a look at our Box drawing instruction.

If an instruction is going to work, then all the openings and tabs must be used. Note that this means that an instruction can't begin with a procedure that has an output. We had better update our definition of an instruction.

Definition of an "Instruction", Version 4: An instruction, in the Logo language, is the name of a procedure followed by its required inputs or a list of procedures each followed by their required inputs. An instruction can not begin with a procedure that has an output, because that output has no where to be used.

Table of Contents | Previous Page | Next Page

 

.