I was looking at another Prolog question on StackOverflow and encountered this situation.
Suppose I have the following facts:
foo(1).
foo(2).
foo(3).
foo(4).
At the SWI Prolog (version 7.4.2) prompt, I exercised this:
2 ?- write('Enter number: '), read(X), nl, foo(Y), Y > X.
Enter number: 1.
X = 1,
Y = 2.
3 ?-
As you can see, SWI Prolog provides one solution with no prompt for additional solutions (which do exist). It does not backtrack.
In GNU Prolog (version 1.4.4), the behavior is more what I would expect:
| ?- write('Enter number: '), read(X), nl, foo(Y), Y > X.
Enter number: 1.
X = 1
Y = 2 ? ;
X = 1
Y = 3 ? ;
X = 1
Y = 4
yes
| ?-
Thanks to @trivelt for a reduction of the problem to simply:
?- foo(X). % Backtracks and finds all solutions for X
?- read(_), foo(X). % Does not backtrack and finds only one solution for X
Is this a bug in the SWI version 7.4.2 implementation? Or are these alternative acceptable/expected behaviors?