2
votes

I'm trying to get comfortable with Prolog (SWI Prolog specifically).

I have this very simple listing:

animal(bear).
animal(mouse).
animal(bird).

Now whenever I ask for all atoms that fulfill (what is the correct expression?) the predicate animal I always get only the first one.

?- animal(X).
X = bear .

Though all three atoms evaluate to 'true' for animal.

?- animal(mouse).
true.

?- animal(bird).
true.

What am I doing wrong? Is this behavior controllable via some setting?

1
Press the semicolon key ; to get further answers.gusbro

1 Answers

0
votes

There is nothing wrong in your code. Prolog is a reasoning machine. So it tries to find the first solution that will satisfy all the variables. Once the solution is found it prints it out.

Now if you need additional solution there should be some combination that you should enter so that prolog will continue searching. If I remember correctly it might be a semicolon...

Hope this helps