If you have relationships such as:
brother(sam, bill).
brother(bill, fred).
And you want to find all of bill's brothers, you'll need to do a little more:
find_all_brothers(Z) :-
findall(X, (brother(X, Z) ; brother(Z, X)), X0), write(X0).
To avoid any redundant members of the list, setof
will sort and provide only unique members:
find_all_brothers(Z) :-
setof(X, (brother(X, Z) ; brother(Z, X)), X0), write(X0).