A command to display blank lines

First steps

Let us start by seeing how we might define a new command which will print two blank lines on the screen when we invoke it. LOGO allows us to call a procedure whatever we like as long as the name is one word. Let us call this one double.space. It is a particularly simple command in that no inputs are required.

to double.space
print [ ]
print [ ]

The body of this definition could just as well be written out - with its two instructions on one line:

print [ ] print [ ]

On the other hand splitting an instruction like print [ ] across two lines, e.g:


[ ] print [ ]


Alternative tactics

The two acceptable formats above are just notational variations of the same definition, but a procedure to achieve a particular goal can also usually be defined in a number of different ways. Even this simple procedure is no exception. What we have suggested is conceivably the simplest approach. The definition is perhaps, however, not entirely as expected. It would not be unreasonable to suppose that moving the cursor down two lines would be handled by instructing LOGO to print two return characters. In fact, it is possible to instruct LOGO to print two returns. But, as you will discover, identifying a return is less easy than identifying an empty list and since print first removes the outermost parentheses of any list before it prints it and also automatically concludes with a return, we have taken advantage of the behaviour of this primitive to achieve a simpler definition of our new command. If you happen to be familiar with BASIC you should note that print print is not a contender because - in most implementations - the LOGO procedure print requires an input.

Selecting the number of blank lines

As it stands, double.space hardly merits the trouble it takes to define it. On the other hand, if the number of line spaces could be varied - if we could say: 'Repeat the printing of the empty list N times' and choose the value of N - it might become more useful.

As it happens, getting LOGO to repeat an instruction or even a series of instructions is not difficult. There is a primitive command repeat which requires two inputs. The first input must be a number (or an expression evaluating to a number) the second must be a list containing one or more instructions. With repeat we could replace the body of double.space in the definitions above by the single instruction

repeat 2 [print [ ] ]

And, changinging the name of the procedure appropriately, we could replace repeat 2 with repeat 3 or repeat 4 ...

Using an input variable for more flexibility

Of course, this is not quite what we are after either. What we need is a definition which allows the number of line spaces to be selected, rather than imposed, when the procedure is invoked. To do that we need to redefine the command so that it accepts an input, the value of which will determine the number of empty lines.

Like procedures, inputs have names. If we call this new procedure line.space and we use the name "times for the input, the first line of the definition will be written as:

to line.space :times

It is important to understand the role of the input name set up by this line. It is the name for a particular type of variable. Our goal is that any user of line.space will be able to say line.space 3 or line.space 25 or line space any.other.expression (as long as any.other.expression is or evaluates to a number). But clearly the instructions making up the procedure cannot refer to any one (still less all!) of these numbers if they are to be formulated in the maximally general way. Instead, in order to achieve the necessary generalisation, the input number - whatever it is - must be represented within the body of the definition by the name of some variable whose current value depends on the input provided when the procedure is invoked. The function of our new first line, therefore, is to declare that the variable name to be assigned to the one (and only) input to the procedure called line.space is the word "times. A rough English paraphrase of the first line might consequently be:

If you are asked to line.space, take the first (and only) input object you are given, call it "times and then do the following . . .

The procedure body which follows this first line need now to be no more complex than:

repeat :times [print [ ] ]

As long as the variable "times has some number as its value, repeat will happily carry out the instruction in its second input exactly that number of times.
If finally we add the required last line end, the complete definition becomes:

to line.space :times
repeat :times [print [ ] ]

An aside on variables

Now would be a good time to check out the status of the input variables which are set up in defining procedures such as line.space. Their behaviour is different in important ways from variable created using make. Look here to find out how. The next page button takes you to Defining operations

Ron Brasington
Department of Linguistic Science
The University of Reading

E-mail: ron.brasington@rdg.ac.uk