3
votes

I have written a predicate common_participant(Person, PairEvent). which returns pairs of facts from my knowledge base. I was wondering whether there is any way to perform variable binding and collect all results without using the semicolon every time.

Thanks,

I.

1
I'm not sure I understand the question. Every time what? - Gian

1 Answers

1
votes

Yes, you can use findall/3. But depending on what you really want to do, there are often better ways. Do you want to output things? Then try this:

print_participants :-
    common_participant(Person, PairEvent),
    write(Person), write(' participates in '), write(PairEvent), write('.'), nl,
    fail.
print_participants :-
    true.

That way, you don't need to keep all combinations in a large list at the same time, but only the one that is needed for printing.

Edit: Fixed the code, as suggested by Kaarel.