Using cut in Prolog is very delicate. Most cuts are essentially incorrect, but work still in certain situations. You could use a cut here, provided you want exactly one answer. But since you want the entire set, you are out of luck: You need to explore all answers to determine that set.
Fortunately, there is an elegant shortcut (pun intended) for that: setof/3
. So ask
?- setof(t, sibling(diane, S), _).
For this usage of setof/3
, the last argument is of no interest. It is actually [t]
.
For a general purpose exists/1
, define
exists(XGoal) :- setof(t, XGoal, _).
This allows the use of existential quantifiers.