Use an error loop:
test(X, 1, 4, 5), writeln(X), fail ; true.
or the same in a more readable way using forall/2:
forall(test(X, 1, 4, 5), writeln(X)).
There is no need to create a list of all solutions (used for this findall/3) if you do not need this list for anything else but print it.
If your Prolog does not forall/2, do it yourself as follows:
forall(A, B) :-
\+ (call(A), \+ call(B)).
source
share