Search code examples
prologprolog-findall

Findall with multiple variables in Prolog


I would like to get a list of solutions from a rule I made in Prolog.

However the findall predicate appears to only work with one variable.

Can anyone suggest how to get around this apparent limitation?

My rule

beat(P,M,E)

What I want

L = [[P,M],[P,M],................]

What I get now

L = [P,P,P,P,.........]

or

L = [M,M,M,M,M.............]

Solution

  • findall can work with a surprisingly flexible amount of variations. I think you want something like this:

    findall([P,M], beat(P,M,E), L).