I'm a beginner in Prolog, and I just want to get the list of all friends of a given person. if i have predicates, like:
friend(hend, khadija).
friend(huda, mariam).
friend(huda, aisha).
friend(huda, lamia).
friend(mariam, hagar).
how can i write a predicate friendList(X,List) that store all friends of given person in List, like:
?- friendList(huda, List).
List = [mariam, aisha, lamia].
I have tried to write this:
friendList(X,[]):-
not(friend(X,_)).
friendList(X,L):-
friend(X,Y),
friendList(X,T),
L = [Y|T].
but I get stack limit error. how can i write it correctly, without built-in predicate?