Take a given database, e.g.
input(80).
input(30).
input(25).
input(90).
Compute the amount of inputs above 50 times 100, constrained to only taking /1 input. e.g.
%compute(?integer).
compute(I).
I = 200 %seeing as input(80) and input(90) matches the condition of being above 50
I have tried the following prolog code to mimick the compute function, unsuccessfully:
compute(I) :- input(G), G>50, I is I+100.
The I+100 does not work as I intend.
Prolog is searching the matches one by one, and returning query result for EACH input, not for all of them. To collect all of the matching values, you can use
bagof
,setof
orfindall
metapredicates. Here is the code that is doing what you have defined: