rebis-dev: Exception mechanism does not work correctly
With rebis-dev, please consider the following interaction:
$ scryer-prolog -f ?- use_module(library(clpz)). true. ?- use_module(library(freeze)). true. ?- freeze(A, true), all_distinct([A]). throw(local_attributes([],[_1734])). clpz:all_distinct([A]), freeze:freeze(A,(true,true)).
The output throw(local_attributes([],[_1734])). which appears in response to the final query is unexpected: An exception of the form local_attributes(_,_) is thrown, and immediately also caught, by library(clpz) in https://github.com/mthom/scryer-prolog/blob/dfebef2e9f9ddbfa2f92cc3796982c4bd47d4442/src/lib/clpz.pl#L6159. Therefore, it ought not to appear on the toplevel.
For comparison, on master I get as expected:
?- freeze(A, true), all_distinct([A]). clpz:all_distinct([A]), freeze:freeze(A,(true,true)).
This example, by itself, seems somewhat contrived. However, this exception occurs in actual programs, for example when creating animations of search processes (N-queens, Sudoku etc.): In such examples, we can use freeze/2 to produce output when a variable becomes bound, and this currently causes the mentioned issue when using rebis-dev.
Generally this is a sign an exception was thrown during goal expansion.
However, we have (in rebis-dev):
$ scryer-prolog ?- use_module(library(clpz)). true. ?- all_distinct([A]). clpz:all_distinct([A])
That is: all_distinct/1 by itself does not throw such an exception. Only in combination with freeze/2 (or other constraints) we see such an exception. This seems to indicate that no such exception arises during goal expansion of all_distinct/1 in this case.
For example, we have:
?- use_module(library(dif)). true. ?- dif(A, B), all_distinct([A]). throw(local_attributes([],[_2060])), unexpected. clpz:all_distinct([A]), dif:dif(A,B), dif:dif(A,_A).
This works correctly now, thank you a lot!