<< >> Up Title Contents

2.1.3. Recursion

The ancestor/2 example discussed above exemplified two crucial properties of a recursive rule or definition. Namely, there are always two components, 1) the base of the recursion

ancestor(P, C) :-
 	parent(P, C).

and 2) the recursion itself

ancestor(A, D):-
	parent(A, C),
	ancestor(C, D).

The base of the recursion is a non-recursive clause, which, in a computational context, tells the computation when to stop. Here the minimal definition of ancestor is a parent. The recursion crucially involves the predicate calling itself.



<< >> Up Title Contents