| Learning and Computing | Education | Computing | Psychology | Artificial Intelligence |

Thinking About Variables

Variables are names which have values assigned to them. A good first way to think about variables is as little boxes, say the kind that are used to keep wooden matches in. Computer memory is made or of these little boxes, each of which may or may not have something in it. Naming the boxes is a good way to keep track of specific boxes into which you put things. When you ask what's in a specific box, for example, :BOX2 (read as "dots Box 2" or "tell me what thing is in Box2"), you don't change what's in the box. When you use the MAKE command, you always CHANGE the contents of the box. You could think of it as emptying the box before packing a new thing in it.

A second important way to think about variables comes from their use as inputs to procedures. You can imagine a procedure as a list of instructions to be performed by a lazy little man. The little man knows how to do what the steps of his procedure specify. He sleeps whenever he is not doing his procedure. He wakes up when somebody calls his name; then he does what he knows how to do and goes back to sleep. The little man never sees other people, but he can get mail in his mail box. This is necessary because he sometimes needs a message to specify exactly how he should execute a command. The message in his mail box when he wakes up is the value of the input variables he needs to perform the steps of his procedure.

A third important way to think about variables comes from their use in controlling the repetition of procedures (whether by looping or by recursion). Here are two ways to draw a square with repetition:

TO SQUARE :COUNT TO SQ :SIDES.LEFT
LABEL "X IF :COUNT = 0 [STOP] IF :SIDES.LEFT = 0 [STOP]
FORWARD 25 RIGHT 90 FORWARD 25 RIGHT 90
MAKE "COUNT (:COUNT -1) SQ (:SIDES.LEFT - 1)
G0 "X END
END SQ 4
SQUARE 4
Executing [SQUARE 4] or [SQ 4], the turtle passes over each side one time. With the variables some other value, the turtle would trace that many sides of a square. In general, such repetition count variables control execution of the steps within a procedure's boundaries.

Summary

variables - permit indirect reference to values which may change -- as one may refer to the contents of a box by naming the box.
input variables - permit specification of values for use by operations within procedures refering to variables -- one may think of them as messages needed by the little man who executes the procedure steps.
repetition-variables - control the number of times procedure steps are executed within their repetition boundary.

Publication notes:


| Learning and Computing | Education | Computing | Psychology | Artificial Intelligence |