Cristof
Cristof

Reputation: 26

Why is this Prolog program returning true AND false?

i'm new to Prolog, and try to understand why this very simple program is return 2 solutions : true AND false. For me, this should return only true, why return false too ?

predicate1(_,[]).
predicate1(X,[_|T]) :- predicate1(X,T).

?- predicate1(abc,[]).

Thanks for your help.

Upvotes: 0

Views: 500

Answers (1)

Paulo Moura
Paulo Moura

Reputation: 18663

Your goal unifies with the first clause (a fact) for the predicate:

?- predicate1(abc,[]) = predicate1(_,[]).
true.

Thus the query returns true as its first result. But a choice-point is created as there's a second clause (a rule) for the predicate. As the unification of the goal and the head of the rule fails, you get false when asking for a second solution:

?- predicate1(abc,[]) = predicate1(X,[_|T]).
false.

Upvotes: 0

Related Questions