~/ learn/ comp-456/ cards/ Programming AI: Prolog (and Lisp idioms)
1 of 29

Type the family-tree facts and the grandparent rule

Type the family-tree facts and the grandparent rule

Answer

parent(tom, bob). parent(bob, ann). parent(bob, pat). grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

The rule body is a conjunction: X is a grandparent of Y if X is a parent of some Z AND Z is a parent of Y. The shared variable Z must unify to the SAME object in both goals — that is how the two parent steps chain together.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/1c2f44cb-da6c-4363-ab31-2566d120352c/flashcard utf-8 LF