I found a little discrepancy. This is my test case:
test(X) :- catch((X=1;X=2), _, true).
test2(X) :- catch((X=1;X=2,throw(3)), X, true).
test3 :- test(X), test(Y), write(X-Y),
write(' '), fail; nl.
test3 :- test2(X), test(Y), write(X-Y),
write(' '), fail; nl.
test3 :- test(X), test2(Y), write(X-Y),
write(' '), fail; nl.
test3 :- test2(X), test2(Y), write(X-Y),
write(' '), fail; nl.
On GNU-Prolog, TauProlog, YAP and XSB I get:
?- test3, fail; true.
1-1 1-2 2-1 2-2
1-1 1-2 3-1 3-2
1-1 1-3 2-1 2-3
1-1 1-3 3-1 3-3
On SWI-Prolog 8.3.26 and ECLiPSe Prolog 7.0 I get:
?- test3, fail; true.
1-1 1-2 2-1 2-2
1-1 1-2
ERROR: Unhandled exception: 3
I guess it has to do with the timing, when the throw ball is unified
with the second catch/3 argument. After bindings are undone or before.
If the binding is still X=2
, then a throw ball 3
doesn’t unify.