0

Started learning Prolog 2 days ago and came across this problem, I'm trying to program both rules at the end but they don't seem to work correctly. What am I doing wrong?

% gender/2: identifies the gender of a person

gender(beto,male).
gender(willy,male).
gender(caonabo,male).
gender(haley,female).
gender(mary,female).
gender(yoli,female).

%friend/2 specifies the friendship between two persons

friend(beto,willy).
friend(willy,caonabo).
friend(willy,haley).
friend(haley,mary).
friend(haley,yoli).

% Rule to know if a person has any female friends
has_fFriend(person):- friend(person,friend),genero(friend,female).


% Rule to know if the person has any friends of it's same gender
homofriend(person):- friend(person,friend), gender(person,X) == gender(friend,X).
2
  • 2
    Variables start with Uppercase or _underscore.
    – CapelliC
    May 9, 2021 at 14:54
  • 1
    In Prolog words starting with small letters are constant. If you want a variable, then you should use a word starting with capital letter. So some thing like has_fFriend(Person) :- friend(Person, Friend), genero(Friend, female). should work.
    – rajashekar
    May 9, 2021 at 14:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.