More complex forms of test
Oh, and there's just one more thing . . .
The decision to take a particular
action may sometimes be based on a simple test. You may cut a pack of cards to see
who deals. You may toss a coin if you can't decide to stay in or go out. One test
decides the outcome. But very often, a decision cannot be reached so easily. If you
remember the case of the Spanish, you will know that it is not enough to determine the
ending of a verb word to ask if its grammatical staus is
first.person or not. You also need to know if it is
singular or not and moreover if it is past or not. It is
only when all of these tests have proved positive that you can start to feel safe
about the form of the word. In fact, even then, you are only half safe, since there
are some other features which come into play. But let's labour the point. Let us
just agree that sometimes a decision will depend on a number of conditions, all of
which must be met.
Or do you want an alternative . . .
Adding one new requirement upon another
is not the only way to combine tests. If you want to select the appropriate sounds to
add to the end of a (regular) English verb stem in order to derive the past tense
form, then you need to check if it the stem ends with a /t/ or with a /d/. If either
one or the other is true - and clearly both together would be an impossibility - then
you add /id/ as a final syllable. (bat becomes batted =
/batid/)
Let's be logical
Logo copes with the piling on of conditions and the
provision of alternatives within conditional instructions by the use of the primitive
predicates, and and or. Despite appearances, these are indeed
procedures. Both normally expect two inputs, which must evaluate to "true or
"false, and as predicates themselves they are restricted to outputting
"true or "false. The following are, therefore, acceptable even if
complex Logo expressions and, since each one reduces in the end to a single
"true or "false, either could be used to provide the test (i.e. the
first input to if) in a conditional instruction.:
and :first.name="donald :last.name="duck
or :first.name="micky
:first.name="minnie
In the first case, and outputs "true if, and only if, both of its inputs
individually output "true, i.e. if :first.name="donald outputs
"true and also :last.name="duck outputs "true . Otherwise it
outputs "false . As for or, it outputs "true if either one or
the other or even both of its inputs output "true. If both output
"false then it too outputs :false.
If you have had any dealings with logic, you will recognise here not only the names
but also the behaviour of two of the connectives of propositional
logic. Logicians are accustomed to set out the inferences which it is
possible to draw when propositions are combined with these connectives by means of
tables called truth tables. The truth table for logical
and which conjoins Proposition 1 (P1) and Proposition
2 (P2) would look like this:

The corresponding table for logical or would be:

In fact you can just as easily view these tables as specifying the output from Logo's
and and or if you take columns P1 and P2 to refer to the inputs to the
procedure and the last column to identify its output. In other words, exactly the
same relationships apply. For that reason, and and or are sometimes
referred to as logical predicates or Boolean predicates.
How to be negative
The connectives of propositional logic include not only
and and or but also not. On the face of it,
connective is an odd choice of terminology in this case, since
not is constucted with only one proposition rather than two. But if that
is hard to swallow, its truth table by way of compensation is inevitably
simpler:
Logo, not surprisingly, matches this connective with a primitive predicate called
not which behaves in the same way. It expects one input, which, like those of
and and or, must evaluate to "true or "false. (Now you
can see why it belongs in the same family.) If its input is evaluates to "true
then not outputs "false and vice-versa.
The advantage of such a
predicate shows up clearly whenever it is necessary to specify something to be done in
all circumstances except one, i.e. where the negative conditions are easier
to specify than the positive ones. Suppose, to take a trivial example, you are
dealing with a language which distinguishes three persons - first (I, we), second
(you) and third (he, she, it) - and suppose that first and second person forms of
verbs behave similarly in some respect. It is clearly less long-winded to check that
thing "person is "first or "second by using not in an
expression such as:
not :person="third
than it is to use or:
or :person="first
:person="second
And this and that and the other
You may have noticed that the correct choice
of ending for a Spanish verb is dependent on more than two tests proving positive.
The solution to this potential problem - given that and and or are
limitied to two inputs - is essentially the same as the one we used to concatenate
more than one object with se in Lonely Hearts. (Look here for a reminder.) Either you
use more than one and (with every and except the last receiving one of
its inputs indirectly from another and): and member? :features "1st and
member? :features "singular member? :features "past
Or you take advantage of
the fact that Logo is happy to accept more (or less) than two inputs to and as
long as you signal your intentions clearly with a left parenthesis before the
procedure name and a right parenthesis after the last of the inputs:
(and member? :features "1st member? :features "singular member? :features
"past)
Whichever method you adopt, the expression will only reduce to
"true when every one of the sub-tests outputs "true.
Or, you will be pleased to hear, is treated in exactly the same way so that
more than two alternatives can be easily accommodated, as in this instruction:
if (or :month="september :month="april :month="june :month="november) [op
30]
Masculine and dative or plural
Sometimes, of course, you might need to combine
and with or and indeed both or either of these with not. For
example, to handle some particular aspect of word structure you might need to
formulate a conditional instruction corresponding to something like like this:
If the word is masculine and dative or plural then suffix something or
other
But notice that this English instruction is dangerously ambiguous. Should a suffix
is be added when the word is either on the one hand (a) both masculine and dative or
on the other hand (b) simply plural? Or does it mean instead that a suffix is to be
added only when the word is (a) of necessity masculine and additionally (b) either
dative or plural? And the problem is aggravated with the introduction of
not:
If the word is not masculine and dative or plural then suffix something or
other
Aggravation and prefixation
It may have bothered you so far to see that
Logo's and and or precede both of their inputs. You must say and
:late? :tired? or or :late? :tired? instead of using the usual English
patterns, late and tired? and late or tired?. In other
words, although Logo allows infixing of the equality predicate (=), it requires
that and and or as well as not are prefixed. The
awkwardness of this convention has its compensations, however. Given the way in which
the Logo interpreter reads and :masc? or :dat? :plural?, there is no
ambiguity. The first input to and is provided by :masc? and the output
of or :dat? :plural? must provide the second. It follows that, in this case,
for and itself to output true, :masc? must output "true and
or :dat? :plural? must output "true. Something quite different, on the
other hand, is expressed by and :masc? or :dat? :plural?
A little
discipline and some first aid
From these examples, you can see clearly that when
you come to formulate a test you must be very clear about what you intend and you must
be careful to use an expression which says just what you intend. But you were warned that Logo expects clear thinking! (If you
want a quick test of your understanding click here.)
You might also feel at this point that you could do with some kind of crutch to help
you step through the construction of a possibly long and complex test structure. If
so, then take advantage of a pair of parentheses. Logo does not mind you using
parentheses redundantly and you at least might find that it helps your reading of a
line if you say or (:masc?) (and :dat? :plural?) instead of the balder or
:masc? and :dat? :plural?. They mean the same thing.
Ron Brasington
Department of Linguistic Science
The University of
Reading
Reading
UK
E-mail: ron.brasington@rdg.ac.uk