1

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.
false
  • 10,264
  • 13
  • 101
  • 209
Rowen McDaniel
  • 169
  • 1
  • 2
  • 11

1 Answers1

1

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.
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • I should have been more clear in my post, I wanted all the solutions generated from calling a predicate `number(X)`. I do not have a list. – Rowen McDaniel Mar 08 '16 at 01:55
  • What do the numbers after `member` and `number` mean? – Rowen McDaniel Mar 08 '16 at 01:58
  • 2
    @RowenMcDaniel `member/2` means that `member` is a functor with 2 arguments. Also, Paulo's solution works even in your case. You just need to think it through: `my_predicate(X), writeq(X), nl. fail.`. `member(X, [1,2,3])` is just an example of a predicate call that generates multiple solutions for `X`. – lurker Mar 08 '16 at 02:55