×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Family Tree Out Of Local Stack Error

Family Tree Out Of Local Stack Error

Family Tree Out Of Local Stack Error

(OP)
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).

RE: Family Tree Out Of Local Stack Error

I think I kinda fixed it.

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) :- male(X),parent(X,Y).

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).
mother(X,Y) :- female(X),parent(X,Y).

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).
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).
 

RE: Family Tree Out Of Local Stack Error

What you need to do is remove these 2 clauses:

CODE

father(X, Y) :- parent(X, Y), male(X).

mother(X, Y) :- parent(X, Y), female(X).

You define some 'father' clauses, you define some 'mother' clauses, the 'father' clause uses the 'parent' clause and the 'parent' clause uses the 'father' clause again. While this is not a conceptual problem, it is a conceptual problem here in your code because you just make these calls with the same parameters, so Prolog will just go in a recursive loop without anything to get him out.

CODE

parent(X, Y) :- father(X, Y).
father(X, Y) :- parent(X, Y), ...

See the problem? When you call parent(sally, rojai) Prolog will call father(sally, rojai) which calls parent(sally, rojai) again and so on.

'father' and 'mother' are defined with concrete facts, so you don't need to define them further using 'parent', because 'parent' is defined in terms of 'father' and 'mother'.

There are still some minor problems in your code, but your main problem is solved by removing those 2 clauses

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close