scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

rebis-dev: Exception mechanism does not work correctly

Open triska opened this issue 3 years ago • 1 comments

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)).

triska avatar Sep 10 '22 15:09 triska

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.

triska avatar Sep 16 '22 16:09 triska

Generally this is a sign an exception was thrown during goal expansion.

mthom avatar Oct 04 '22 15:10 mthom

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).

triska avatar Oct 04 '22 17:10 triska

This works correctly now, thank you a lot!

triska avatar Oct 23 '22 07:10 triska