next up previous contents
Next: Predicates and recognizer Up: CHAPTER.2: INTRODUCTION TO Previous: Introduction to printing

Conditionals and conditions

One of the things which makes computers so versatile is their ability to decide for themselves what to do, instead of always doing exactly what they are told. This often depends on the use of conditionals, i.e. commands to do something if something is true. Pop-11 includes conditionals, of which a simple form would be

    if <condition> then <imperative> endif
for example,

    if x = 10 then x => endif;
which will print out the value of x, if it is 10, and do nothing otherwise. Conditionals must include a `condition' between "if" and "then", and may include any arbitrary Pop-11 imperative (which may be a sequence of imperatives) after "then". Conditionals are often typed over several lines when they are more complicated than the above example. For instance:

    if x = 10 and y > 19
    or member(x, list)
    then
        x =>
    endif
A condition is an expression whose value is either the object TRUE or the object FALSE. These are called `boolean' objects, of which there are exactly two in Pop-11. (They are named after George Boole the logician.) There are two built in system names, "true" and "false" which refer to the booleans. They print out as <true> and <false>.

    true =>
    ** <true>
    false =>
    ** <false>
In the above conditional, the expression `x = 10' could serve as a CONDITION, because its value will be either true or false. E.g.

    vars x;
    99 -> x;
    x = 10 =>
    ** <false>
This in turn is because the infix operation symbol `=' denotes a procedure which always returns a BOOLEAN. It compares its two arguments, and if they are the same the result is true, otherwise false. (Strictly speaking "=" is more complex than this, since the type of comparison it performs can be made to depend on the types of objects compared, as explained in HELP CLASSES and REF KEYS. A more detailed explanation of how "=" compares complex structures is provided in HELP EQUAL.)



Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998