Logo instructions

The syntax of instructions

An instruction is issued in a LOGO conversation - at toplevel - by typing a sentence which begins with a command and normally ends, depending on your particular implementation, with either a press of the enter key or a press of return (footnote).

Just as in English, a LOGO instruction may sometimes contain nothing more than one command word. Stop! forms all by itself a complete instruction in English and stop is also a complete instruction in LOGO.(footnote)

But, although stop is complete in itself, you will find that certain command words in LOGO require objects before they make sense, in the same way that English Drop! needs some indication of what to drop and Put! is not complete if you do not say both what to put and where to put it. Print, for example, is the name of a LOGO command, but to form an instruction using print, the command must be provided with (must be followed by) an object to operate on. Print "cat - with a space between print and "cat - is a complete instruction. It causes the word CAT to be printed on the screen at the current cursor position and then moves the cursor to the start of the next screen line. Make as the conversation transcript shows is more like English put. It needs to be followed by two things. In LOGO, paraphrasing loosely, you have to say make something (take the value) somevalue, or to paraphrase from a different viewpoint make something (be the name of) something. More specifically, in raw LOGO, the first example of the conversation transcript examples has the form: make "vehicle "car - which you could flesh out in English as Make vehicle take the value car.

Looked at from a natural language point of view a LOGO command word like print or make is a verb-like word and the LOGO objects we choose to construct with it, in order to make a grammatically correct instruction, are noun-like elements. Using more conventional LOGO-speak, however, we will talk of a verb-like word as the name of a procedure and the noun-like objects, to reflect their function, as inputs to the procedure.

In the instruction print "cat you will notice that the procedure name and its input are distinguished by more than just standard alphabetic characters. In particular, cat is preceded by a double quote mark. Such marks are important. LOGO treats any unquoted word as the name of a procedure and immediately tries to recall what it means. If you type print cat it will have no difficulty with print, but (unless you have previously taught it some procedure named cat) it will respond with I DON'T KNOW HOW TO CAT (exactly in the way it responded to smile, in the sample conversation) or, in Terrapin LOGO with, THERE IS NO PROCEDURE NAMED CAT. The double quote in print "cat is a signal to LOGO not to attempt any interpretation or evaluation of the word it precedes but simply to take it at face value, literally (as a sequence of letters). Opening square brackets at the start of a list perform exactly the same function. Except in some special circumstances, LOGO makes no attempt to treat words in lists as names of procedures.(footnote)

Commands and operations

On start-up, LOGO recognizes only a few words and they are with scarcely an exception verb-like words, i.e. names for procedures. These built-in vocabulary items are called primitives. We have so far looked at examples of one type of primitive procedure - the command which begins an instruction. Commands have effects. The command print makes something appear on the screen. The second type of procedure provided by LOGO is the operation. The defining characteristic of an operation is that it has an output. An operation may also have one or more inputs but it will have one and only one output. Last, despite its non verb-like appearance, is a primitive operation. It requires one input which may be a word or a list written after the procedure name with an intervening space, e.g. last "cat or last [cat dog]. If you give last as its input the list [cat dog], it outputs - or returns - the last element of the input, viz. the word "dog.

The nature of outputs

You will notice that the kind of thing thing that last outputs, in this example, is a normal Logo object. Last, when offered [cat dog] as input, outputs a normal Logo word. Last, when given [[siamese cat] [mongrel dog]] as input, outputs a normal Logo list. And if you think that last, when given "dog, outputs the letter g, then think again. "g is (of course!) a normal Logo word, even if only a word of one character. Every possible output of last, then, is just an normal Logo object and in that respect is exactly the same sort of thing as any input required by a Logo procedure.

Now this characteristic of its output is not just a peculiar property of last. The typological identity of inputs and outputs is quite general in Logo. Operations always output precisely the sorts of data object which LOGO expects to find acting as inputs. In other words, operations always output (or return) either words or lists And this coincidence in type between inputs and outputs has important consequences. It is no accident. It has the effect that the output of any procedure is potentially an input to another, and it is in this possibility that lies much of the power of LOGO. A simple example will give an initial idea of the possibilities which are opened up. As we have seen, the expression last [cat dog] generates the output "dog. In so far as it is a word, "dog is an acceptable input to the primitive operation first which, as you will have guessed, returns the first element of its input. This being so, LOGO allows us - if we so wish - to write a more complex expression first last [cat dog] which interconnects the two procedures. This new expression can be expanded straightforwardly enough into English as the first element of the last element of the list [cat dog], which amounts, of course, to "d. Moreover, even if it is more complex than previous examples, the expression follows in essence the pattern we have already met. As we have seen, any direct inputs to a procedure, in the form of words or lists, are specified immediately after the procedure name. All we need in order to make sense of expressions involving indirect inputs is to accept an extension of this basic principle as follows:

Any procedure name may be followed either

1) in the direct case, by as many objects as required, or

2) in the indirect case, by as many procedures (together with their own inputs) as are required to return or pass on the appropriate objects.

It is on the basis of this mechanism for constructing complex expressions out of simple ones, that we can also build complex instructions such as print last "cat. With rather more daring you could try print first first last [beaune k6 [ [dijon 45] [ch‰lon.sur.sa™ne 30] [pouilly.en.auxois 46] [seurre 26] ] ] which LOGO will accept without complaint.

Reading difficulties?

Of course - and particularly at first - you will find that interactions between procedures, as they become complex, are sometimes difficult to keep in mind when reading a long instruction line. For this reason we will from time to time use pictures called procedure diagrams to help make clear what is going on . For a description of the pictorial conventions used, look here. Soon, with practice, you will find that you can process Logo lines involving primitives almost as efficiently as the interpreter!

What happens to an output

So far, we have observed that the output of an operation is the appropriate kind of element to act as an input to another procedure. It is equally important to be aware that acting as an input is, in fact, the only rôle open to a procedure output. The output of an operation must be passed to another procedure.

This requirement that an output must be dealt with explains why a grammatically acceptable LOGO instruction must begin with a command. A command outputs nothing - it therefore creates nothing which needs passing to another procedure.

The requirement also explains why most implementations of LOGO complain when anything like first "cat is typed in at the keyboard (at toplevel). LOGO complains because there is in this case no procedure to accept the output of first. The output is left in limbo. An error message like YOU DON'T SAY WHAT TO DO WITH C is, therefore, quite justified. (Terrapin LOGO unfortunately is at first sight more forgiving. Its response in the same circumstances is RESULT: C. But this too, despite appearances, is still an error message as you should be able to discover.)

Expressions and instructions

The term expression was used earlier in an informal way to refer to structures made up of operation names followed by as many lists or words as required to provide the necessary inputs. In view of the functional equivalence of a directly identified object (such as the word "dog.) and an operation together with its inputs (such as first [dog cat] which generates the output word "dog), it is clearly convenient to use the same term to refer to both types of structure. In fact, it is normal to identify them both as instances of LOGO expressions. A Logo expression is in other words something which either is or which behaves as (we will normally say evaluates to) an object. Although it would be redundant, we could make this equivalence explicit in our diagrams by representing a word like "dog using the same type of diagram as for an operation but without a procedure name:

Under these conventions, we could talk of expression diagrams being characterized by having an output box at the top(footnote).

Terminological review

A LOGO expression functions as an object and is, in form, either literally an object (a double-quoted word or a list) or an operation followed by as many expressions as are needed to provide its inputs.

(The partial circularity of this definition nicely draws attention to the possibility of an operation being provided with an input by another operation which itself is provided with an input by another operation . . . and so on, until at some point down the line direct inputs are specified.)

Given a definition of the term expression, instruction can be easily defined:

An instruction is a command followed by as many expressions as are needed to provide its inputs.

The function of an instruction is to get something done. Interaction with Logo is mediated by instructions.



[Note 1] The qualification normally is introduced to cover the fact that the user can issue - as if in one breath - a whole series of instructions before pressing enter or return. In this light, the key press really means O.K. That's what I want. Please take notice (and do it!). [Go back]

[Note 2] As it happens, you will never actually use stop in conversational mode because LOGO will not stop to listen to you until it has finished carrying out your last instruction or, in the last resort, until it has been forcibly stopped by a drastic arm-bending technique which you will learn about quite soon. Saying stop in a conversation is therefore pointless. [Go back]

[Note 3] It might seem at this point that the quoting of words is an unnecessary complication. If LOGO knows what print means and what input it requires then it should have no more difficulty with print cat than we do with the English equivalent. You will soon discover, however, that inputs to procedures are not always provided as directly as this - see the next section - and in such circumstances the quotes are clearly needed. [Go back]

[Note 4] This explains why LOGO also complains You don't say what to do with dog - or in Terrapin LOGO's case says Result: dog - if you just type "dog at the keyboard.[Go back]



Ron Brasington
Department of Linguistic Science
The University of Reading
Reading
UK

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

˙