Question: Rewrite your family database, but this time use PROLOG's lists ([H|T]) to represent the basic facts of your family. Save it as an ordinary text
Rewrite your family database, but this time use PROLOG's lists ([H|T]) to represent the basic facts of your family. Save it as an ordinary text file named familylists.pro.
Your program should implement the following facts for your immediate family, grandparents, and great-grandparents.
family([mom,dad],[[daughter1, daughter2],[son1,son2]]).
In other words, each nuclear family is comprised of two lists: family(ParentList, ChildrenList). The ParentList is formatted with the name of the mother, followed by the name of the father. The ChildrenList consists of two sublists, the first giving the names of the daughters, in chronological order, and the second giving the names of the sons, in chronological order.
All other predicates should be defined in terms of the above facts. For example, consider the following definitions:
father_of(D,C) :- family([_,D],[Ds,Ss]),
(member(C,Ds);
member(C,Ss)).
parent_of(P,C) :- father_of(P,C).
parent_of(P,C) :- mother_of(P,C).
male(M) :- family([_,M],_).
male(M) :- family(_,[_,Ss]), member(M,Ss).
member(M,[M|_]). % base case
member(M,[H|T] :- member(M,T). % recursive case
Define the following predicates for your database:
predicate interpretation
--------- --------------
father_of(X,Y) X is the father of Y
mother_of(X,Y) X is the mother of Y
son_of(X,Y) X is the son of Y
daughter_of(X,Y) X is the daughter of Y
sibling_of(X,Y) X is the sibling of Y
brother_of(X,Y) X is the brother of Y
sister_of(X,Y) X is the sister of Y
grandparent_of(X,Y) X is the grandparent of Y
ancestor_of(X,Y) X is the ancestor of Y
oldest_son(S,P) S is the oldest son of P
oldest_daughter(D,P) D is the oldest daughter of P
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
