Conditions and Predicates

In some cases, the program has to test some conditions in order to select one of the alternative courses of action.

The exact way in which conditions can be written and tested depends on the programming language. As far as Refal Plus is concerned, we use the following terminology.

A path Q is said to be a condition, if the value returned by the path is always either an empty ground expression or a failure. If the result is an empty expression, the condition is considered to be satisfied, otherwise, if the result is a failure, the condition is considered not to be satisfied.

Thus empty expressions and failures may be considered as corresponding to the well-known truth values "true" and "false", respectively.

It should be kept in mind, however, that the evaluation of a condition Q may non-terminate or produce an error, in which case we consider either the program or the input data to be incorrect.

Some of the library functions are specifically designed for testing conditions. Such functions are referred to as predicates. In Refal Plus a predicate returns either an empty expression (if its arguments satisfy the condition) or a failure (if the condition is not satisfied). For example, the function Lt tests whether the first argument is less than the second one. In other words, let Ge1 and Ge2 be ground expressions. Then if Ge1 is "less" than Ge2, the result of evaluating <Lt (Ge1)(Ge2)> is an empty expressions, otherwise the result is a failure.

If a program defines a predicate function, the declaration of the function must have the form
    $func? Fname Fin = ;

Now we consider several ways of using and combining conditions.