Search code examples
syntaxprologprolog-toplevel

How to automate semicolon in Prolog


I am learning about Prolog in class and was shown a way to automatically press the semicolon key until there are no more solutions. I have tried searching on Google but I get examples using findall which is not what was shown. Are there any other ways to automatically press ; in the Prolog shell?

For example, showing all the solutions without pressing ; repeatedly.

X = one ;
X = two ;
X = three ;
X = four.

Solution

  • A simple solution, using the member/2 for exemplifying, is to use the fail/0 predicate after the goal:

    ?- member(X, [1,2,3]), writeq(X), nl, fail.
    1
    2
    3
    false.