Before looking at other examples of recursion, it will be helpful to look at
operators, because these are used in Prolog arithmetic. The basic
arithmetic operations of addition, subtraction, multiplication etc., could be
treated as predicates within the kind of Prolog style you have encountered so
far. Addition, for example, might look like this:
+(X, Y, Z)
where X and Y are the arguments to be added, and Z
is the result of the addition. Indeed, some Prologs allow you to do addition
like this. Many more Prologs, however, define arithmetical operations in a way
which is much more like the standard conventions, and write the above equation
as
Z is X + Y
This is a novel format, because it writes the predicate symbols is and
+ between their arguments, without brackets. This is because these two
symbols have been defined within Prolog as infix operators.
In working
with operators, we need to pay attention to two factors: precedence and
associativity.