From the output you show, I assume you are using GNU Prolog. But, first just an important remark:
The cut you placed does not cut as you intend it! In fact, it does not even prevent that there is a single answer. Here is evidence for that:
| ?- member1(X,[1,2,3]).
X = 1 ? ;
X = 2
yes
So you still have two answers. As a rule of thumb: a cut after a recursive goal often does some unexpected things.
If you insist to have exactly the first answer, simply say once(member(X,[1,2,3]))
. The once/1
is effectively a cut, too, but quite in disguise. It is tamed to do exactly one thing. Yes, you can place also cuts into recursive rules, but for a beginner, better leave that to a later lesson.
Behind all this there is another point, which is less visible: The toplevel shell of GNU Prolog will ask you for further solutions if it sees an open alternative (jargon: choicepoint). So when GNU asks you for more, it knows that some part has yet to be explored, but there is no guarantee, that there is actually another answer:
?- member(1-X,[1-a,2-b,3-c]).
X = a ? ;
no
Here, the toplevel sees an open choicepoint and thus asks if you want to explore the query any further. Alas, this search is in vein...
true
? Τrue means that 3 is a member of the list [3,2,3]. The second true is that the query found it again in the list. ` member1(2,[3,2,3]).` would give you only one true. – Dendritic;
), it would stop backtracking – Dendritic