Recursive predicate definitions
If you have not already done so, do the exercise about family relationships.
Extend the family tree that you defined in that exercise by adding great-grandparents for Harry.
Now, define a predicate
ancestor_of/2
. ancestor_of(X,Y)
should
be true if X
is an ancestor of Y
.
Your predicate definition should work correctly even if you add
Harry's great-great-grandparents, his
great-great-great-grandparents, his great-great-... to the
knowledge base.
Ask queries to test your definition. For example:
- Is Albert an ancestor of Harry?
- Who are the ancestors of Harry?
- Is Dudley an ancestor of Harry?
- Who are the descendants of james?
Ctrl-c
. Then type a
to abort.