bsplitkids
Programmer
I am learning the prolog language and I'm starting with the family tree. When I try to ask different questions I get errors. For instance when I asked was sally the parent of rojai parent(sally,rojai). I got this error message ERROR: Out of local stack
Exception: (310,003) parent(sally, rojai) ? Iooked this error up online and I saw that it had to do with recursion, but I dont know how to fix it. I also got this error when I tried the following:
granddaughter(janae,sheri).
parent(sally,Y).
uncle(desmond,Y).
Does it have something to do with the order of my rules or the parent rule itsself?
The following code:
father(james,sheri).
father(ij,rojai).
father(michael,pam).
father(michael,desmond).
father(michael,tonya).
father(rojai,janae).
father(rojai,imani).
father(desmond,tyson).
father(desmond,miya).
father(desmond,demonica).
father(jason,taylor).
father(jason,bria).
father(X,Y) :- parent(X,Y), male(X).
mother(gwendolyn,sheri).
mother(sally,rojai).
mother(sheri,pam).
mother(sheri,desmond).
mother(sheri,tonya).
mother(pam,janae).
mother(pam,imani).
mother(cheri,tyson).
mother(cheri,miya).
mother(cheri,demonica).
mother(tonya,taylor).
mother(tonya,bria).
male(desmond).
male(james).
male(ij).
male(rojai).
male(tyson).
male(jason).
female(sheri).
female(pam).
female(tonya).
female(janae).
female(imani).
female(miya).
female(demonica).
female(taylor).
female(bria).
female(gwendolyn).
female(cheri).
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
mother(X,Y) :- parent(X,Y),female(X).
grandparent(X,Y) :- parent(X,Z),parent(Z,Y).
granddaughter(X,Y) :- female(X),grandparent(Y,X).
sibling(X,Y) :- parent(Z,X),parent(Z,Y),X\==Y.
brother(X,Y) :- sibling(X,Y),male(X),X\==Y.
sister(X,Y) :- sibling(X,Y),female(X),X\==Y.
uncle(X,Y) :- male(X),sibling(X,Z),parent(Z,Y).
aunt(X,Y) :- female(X),sibling(X,Z),parent(Z,Y).
niece(X,Y) :- female(X),sibling(Z,Y),parent(Z,X).
Exception: (310,003) parent(sally, rojai) ? Iooked this error up online and I saw that it had to do with recursion, but I dont know how to fix it. I also got this error when I tried the following:
granddaughter(janae,sheri).
parent(sally,Y).
uncle(desmond,Y).
Does it have something to do with the order of my rules or the parent rule itsself?
The following code:
father(james,sheri).
father(ij,rojai).
father(michael,pam).
father(michael,desmond).
father(michael,tonya).
father(rojai,janae).
father(rojai,imani).
father(desmond,tyson).
father(desmond,miya).
father(desmond,demonica).
father(jason,taylor).
father(jason,bria).
father(X,Y) :- parent(X,Y), male(X).
mother(gwendolyn,sheri).
mother(sally,rojai).
mother(sheri,pam).
mother(sheri,desmond).
mother(sheri,tonya).
mother(pam,janae).
mother(pam,imani).
mother(cheri,tyson).
mother(cheri,miya).
mother(cheri,demonica).
mother(tonya,taylor).
mother(tonya,bria).
male(desmond).
male(james).
male(ij).
male(rojai).
male(tyson).
male(jason).
female(sheri).
female(pam).
female(tonya).
female(janae).
female(imani).
female(miya).
female(demonica).
female(taylor).
female(bria).
female(gwendolyn).
female(cheri).
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
mother(X,Y) :- parent(X,Y),female(X).
grandparent(X,Y) :- parent(X,Z),parent(Z,Y).
granddaughter(X,Y) :- female(X),grandparent(Y,X).
sibling(X,Y) :- parent(Z,X),parent(Z,Y),X\==Y.
brother(X,Y) :- sibling(X,Y),male(X),X\==Y.
sister(X,Y) :- sibling(X,Y),female(X),X\==Y.
uncle(X,Y) :- male(X),sibling(X,Z),parent(Z,Y).
aunt(X,Y) :- female(X),sibling(X,Z),parent(Z,Y).
niece(X,Y) :- female(X),sibling(Z,Y),parent(Z,X).