Imposing conditions

Sometimes a choice must be made

The simple linear organisation of events within Lonely Hearts contrasts sharply with situations where a choice, a decision has to be made.

Suppose that once in a while you arrive early for lunch at your usual eating place and find that the full menu is on. What do you do? You consider the situation, chew over the relevant facts, and then act appropriately. Mm! It's hot today, so I'll just have a salad or perhapsIt's a long time since breakfast. I'll start with . . . and then have some of that . . .. In designing any sizable LOGO microworld you will frequently find it necessary to replicate this tactic of inspecting the circumstances (testing the water, examining the data) and then proceeding accordingly.

Spanish verb forms

Just suppose, for example, that you want to develop a tool to help an English speaking language learner (in a way that a dictionary typically does not help him) with the variety of verb forms he will need to produce in writing a language like Spanish. Corresponding to the single English word spoke, Spanish deploys a veritable battery of word structures with quite different endings for referring to events in the past. They include: hablé - for I - hablaste - for you (familiar) - habló - for he, she or you (more formal) - hablamos - for we - hablásteis - for you all (familiar) - and hablaron - for they or you all (more formal). It would clearly be very useful to have a procedure translate which could accept inputs like [I spoke] [you all will leave] and respond with the corresponding Spanish verb form.

Whatever you may think, that is a tall order, and, in making a start, we would do well to simplify the task initially. We might perhaps reduce the complication (from the programming point of view) by requiring the English forms to be identified using grammatical terminology like [first.person singular past speak] [second.person plural future leave] - this sidesteps the problem of getting the system to figure out what the English forms mean. We could also simplify things by ignoring for the moment the fact that Spanish verbs belong to a range of different groups or classes each of which uses different endings for the same meanings. (So too do various irregular verbs which we could likewise avoid.) But even setting our sights low in this way, translate is still going to need to react differentially to whatever lists we give it as input. If the input contains first.person and and singular and past, then translate should output the base of the appropriate verb with é added to its end. But if the input contains second.person and plural and future then the output should be the base plus -areis. The procedure, in other words, will need the capability to test its input against certain conditions and react differently depending on the result of the tests.

If . . . (then)

You will certainly have guessed that LOGO has a primitive designed precisely for this role. It has the name if. If is used to create decision points, or branches in the flow of control which lead sometimes through this set of instructions and sometimes through that.

If we take a closer look, we will see that if is a command which accepts either two or three inputs. (In some versions of LOGO, the three input form is distinguished by having a different name, ifelse, but its workings are the same.)

The first input to if is a test. A test is a Logo expression which evaluates to (either is or reduces to) the word "true or the word "false. In other words it is like a question which gets the answer yes or the answer no.

The second input is a list containing instructions - perfectly normal Logo instructions - which are to be followed if the test outputs "true (if the condition is met, if the answer is yes).

The third (optional) input is a list of instructions - again normal Logo instructions - which are to be followed if the test outputs "false (if the condition is not met, if the answer is no).

Abstracting away from any particular content, then, the form of an instruction beginning with if can be schematized as either

if test []


if test [] []

If you feel the need to put some content into this, well then if tired? [] [] is a perfectly acceptable LOGO instruction (as long as you have defined a test tired? and two procedures, one called, the other

Constructing tests and managing the flow of control

There are, clearly, two new things to learn about in order to use the conditional command if:

You will probably find it best to look first at form of tests (on the next page) and then more closely at the way in which the flow of control may engineered (and varied) by the use of different if.constructions.

Ron Brasington
Department of Linguistic Science
The University of Reading