As lurker already explained, the question is whether the Prolog system knows that there is no further answer or it does not know (yet).
- If the Prolog system knows that there is no further answer, and there was at least one answer, it prints yes after the last answer and does not wait for you to decide whether you would like another answer (since there is none).
- If the Prolog system does not know whether there are more answers, you can press ";" to let Prolog search for more answers. If it does not find one, it will print "no", because it failed to satisfy your modified query ("are there more answers?").
In the case of your query female(X), the program clauses were exhausted: There are no more clauses about female. Therefore, it was clear that there cannot be more answers.
In the case of the query parent(X, bob), there are more facts about parent when the system found the answer X=alice. The Prolog system just stopped in the proof execution at this point. It does NOT first compute all answers and then shows them one by one.
When you pressed ";", Prolog continues with the next fact parent(alice, betsy). However, the second argument of the predicate does not match, therefore it tries the following fact and so on. In the end, all facts about parent are exhausted, without any other answer found. Therefore Prolog reports failure by printing "no".
Most Prolog systems have index structures to speed up search. Therefore, you might notice that not always all rules are tried. For instance, you might check parent(alice, X). Depending on your Prolog system, it might be that Prolog immediately stops after the three answers. This would show that it has an index on the (outermost functor of the) first argument of every predicate, which is quite common.
?
after a solution, that means it has more options to explore, which may or may not succeed. If you press;
, Prolog attempts the option and, if falis to find additional solutions, says "no". If you don't get the?
prompt, that means there was no choice point and Prolog just responds 'yes'. – Venitavenite