Hi I'm new to prolog and I was trying to create a basic family tree so fair i have this:
/* Database for family. It consists of facts and rules. */
/* Facts */
female(ella).
female(jodi).
female(sonya).
male(arnold).
male(chris).
male(louis).
male(mark).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).
mother_of(ella, sonya).
mother_of(jodi, ella).
mother_of(jodi, mark).
/* Rules */
grandmother_of(X, Z) :-
mother_of(X, Y),
(mother_of(Y, Z); father_of(Y, Z)).
familyquestions :-
grandmother_of(X, arnold),
write('The grandmother of Arnold is '), write(X), nl,
father_of(Y, mark),
write(Y), write(' is the father of Mark'), nl, nl.
However, I was trying to do this:
Define (Add into the database) a rule called is_male(X) that returns "yes" (or "true") if X is the father of somebody.
Note, the system will return a "yes", if it finds a "true" answer and there exist no more true answers. The system will return "true ?" if it finds a "true" answer and there are still possibly further matches. In
this case, if you type "enter", it will return "yes" and stop. If you type ";", it will continue to search for further answers.
1.2 Define a rule called is_female(X) that returns "yes" or "true" if X is the mother of somebody.
1.3 Remove (comment out) the facts that are not essential (have been covered by the new rules is_male/1 and is_female/1) you have added to the database.
So I added this
/* Database for family. It consists of facts and rules. */
/* Facts */
female(ella).
female(jodi).
female(sonya).
male(arnold).
male(chris).
male(louis).
male(mark).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).
mother_of(ella, sonya).
mother_of(jodi, ella).
mother_of(jodi, mark).
/* Rules */
grandmother_of(X, Z) :-
mother_of(X, Y),
(mother_of(Y, Z); father_of(Y, Z)).
is_male(X, Y) :-
father_of(X, Y).
is_female(X, Y) :-
mother_of(X, Y).
familyquestions :-
grandmother_of(X, arnold),
write('The grandmother of Arnold is '), write(X), nl,
father_of(Y, mark),
write(Y), write(' is the father of Mark'), nl, nl.
but when i ran it, it gave me this code: uncaught exception: error(existence_error(procedure,is_male/1),top_level/0)