next up previous
Next: Golden Rules of recursion Up: No Title Previous: Membership

Mamma's and Pappa's

ancestor(X,A) :-
  parent(X,A).

ancestor(X,A) :-
  parent(P,X),
  ancestor(P,A).

parent(a,b).
parent(b,c).

Q : ancestor(X,A)
A : X = b, A = a
X = c, A = b,
X = c, A = a
no more solutions

If the ancestor relation is defined differently :

ancestor(X,A) :-
 ancestor(P, A),
 parent(P,X).

ancestor(X,A) :-
 parent(A,X).

parent(a,b).
parent(b,c).

Q : ancestor(X,A)
A : (WAIT!)



Omer F Rana
Thu Feb 13 19:58:14 GMT 1997