Moving variables in Prolog

I wrote a predicate common_participant(Person, PairEvent). which returns a couple of facts from my knowledge base. I was wondering if there is a way to bind variables and collect all the results without using a semicolon every time.

Thank,

I am.

+3
source share
1 answer

Yes you can use findall/3. But depending on what you really want to do, there are often better ways. Do you want to bring something out? Then try the following:

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

Thus, you do not need to save all the combinations in a large list at the same time, but only the one that is necessary for printing. A.

: , Kaarel.

+1

Source: https://habr.com/ru/post/1756012/


All Articles