Reputation: 125
I'm new to Prolog so I'm completely unaware of the errors i get. I'm making a code that describes the relationship between any two family members. i.e if two are married, sisters, brothers, sister and brother...etc.
wife(hussein,amina).
mother(amina,amira).
mother(amina,amany).
mother(amina,amna).
mother(amina,hassan).
mother(amina,hossam).
father(hussein,amira).
father(hussein,amany).
father(hussein,amna).
father(hussein,hassan).
father(hussein,hossam).
parent(X,Y):-
mother(X,Y) ; father(X,Y).
married(X,Y) :- wife(X,Y).
sibling(X,Y) :-
mother(Out1,X),
father(Out2,X),
mother(Out3,Y),
father(Out4,Y),
Out1 is Out3,Out2 is Out4.
The code works fine for the parent,married rules but i can't get why the sibling isn't working. I get for X and Y variables their mothers and make sure they're the same, their fathers and make sure they're the same to confirm they're siblings. but i get this error :
ERROR: is/2: Arithmetic: `amina/0' is not a function
Upvotes: 2
Views: 2822
Reputation: 66210
is/2
is for arithmetc; with is you can write something like
X is 3 + Y
so X
is unified with 3 plus the arithmetic value of Y
.
But, in you case, the terms you're using (hussein
, amina
, amira
, etc.) aren't numbers so you can't use is
for unify they.
You, in sibling/2
, can "unify" Out1
with Out3
and Out2
with Out4
using a equal (=
operator)
sibling(X,Y) :-
mother(Out1,X),
father(Out2,X),
mother(Out3,Y),
father(Out4,Y),
Out1 = Out3,
Out2 = Out4.
or better (IMHO) usign the same variable (using Out1
instead of Out3
and Out2
instead Out4
)
sibling(X,Y) :-
mother(Out1,X),
father(Out2,X),
mother(Out1,Y),
father(Out2,Y).
Upvotes: 1