I encountered a Prolog program containing a nested if-then-else of the form
p(X,Y) :-
(cond1(X,Y) -> q(X)); true,
(cond2(X,Y) -> q(Y)); true.
that had unexpected answers. The reason for this behaviour is the same as in the following queries:
?- (true, (true -> X=a)); X=b.
X = a ;
X = b.
?- ((true -> X=a), true); X=b.
X = a ;
X = b.
?- (true -> X=a); X=b.
X = a.
The first query has two answers but the second one has only one.
P.S.: I know the difference, but I have not found a SO question that deals with this quite confusing phenomenon. So why not have it documented this way?
Aucun commentaire:
Enregistrer un commentaire