A strange behavior of CHR package

This is a further discussion about the issue on Github.

For the following program

%% test.pl 
:- use_module(library(chr)).
:- chr_constraint c/2.

c(K,_I), c(K,_J) <=> writeln('rule 1 fired').
c(_I,K), c(_J,K) <=> writeln('rule 2 fired').
?- consult(["test.pl"]).
true.

?- c(X,Y).
rule 2 fired
c($VAR(X),$VAR(Y)).

Although the 2nd rule has two heads and I only added one constraint c(X,Y), the rule still fired (?). This should be considered an unexpected behavior.

The expected behavior is

?- c(X,Y).
c($VAR(X),$VAR(Y)).

The “rule 2 fired” should not be printed, because there is only one constraint. It could matches the 1st constraint at head, but no partner constraint in the store.

Thanks.

Note that apparently the behaviour changed from v7.2 to v7.3 of SWI-Prolog. v7.2:

> swivm use 7.2
Now using SWI-Prolog v7.2.3
> swipl -s test.pl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- c(X,Y).
c(_G39140,_G39150)
true .
c(_G39140,_G39150)

v7.3:

> swivm use 7.3
Now using SWI-Prolog v7.3.35
> swipl -s test.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 7.3.35)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- c(X,Y).
rule 2 fired
c(X, Y).
3 Likes

There are quite a few changes in CHR between these two versions as well. Unfortunately the build system is different which makes bisecting non-trivial :frowning:

1 Like

Did Leuven make major changes? I guess the 2 directions to find the cause are
a) put their changes into the previous SWI build
b) check the newest SWI with the previous CHR code.