views:

40

answers:

1

Hi all, 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  A: 

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.

Roland Illig
Your print_participants/0 doesn't print all the solutions unless you use the semicolon (which the OP wanted to avoid), or call it as "print_participants, fail ; true."
Kaarel
I fixed the code. By the way, I interpreted the question like "I don't want to press the semicolon key all the time, just to get all answers". Therefore I think a semicolon in the code doesn't matter.
Roland Illig
Yes, that is what I meant Roland, thank you so much. It works fine.
Idioma