My query may return different values. I would like to find their amount. Example

test(1). test(2). 

What request do I need to make to get an answer of 3?

  • I had to think about how to apply findall (Variable, Atom, ListVariable) to my example. Well, specifically for me it will be findall (X, test (X), L), which will return me X = X and L = [1,2]. Then it remains to sum up the elements of the sheet. Thank you, the issue is resolved. - E. Kochkurov

1 answer 1

Your question is not entirely clear. Do you have a base of facts and rules in the form of a single predicate that can return multiple solutions and you need to find the sum of all the decisions?

If yes, then we can take the built-in predicate findall (Variable, Atom, ListVariable), which forms a list of all their solutions (3 arguments). And then you can sum up the entire list.