scryer-prolog
scryer-prolog copied to clipboard
Odd dif/2 residual with cyclic list
$ scryer-prolog ?- L=[1|L], dif(L, B). L = [1|L], dif:dif([1|1],B). ?-
How to test for this? So far, I compared roughly all permutations of (=)/2
and dif/2
goals. They all should produce either the same failure, unconditional success, or conditional success. What is the exact criterion here? Somehow involving copy_term/3
.
For reference, the residual is the same with both permutations in this case:
?- L = [1|L], dif(L, B).
L = [1|L], dif:dif([1|1],B). % Unexpected
?- dif(L, B), L = [1|L].
L = [1|L], dif:dif([1|1],B). % Unexpected
I assume the correct behavior here would be:
?- dif(L, B), L = [1|L].
L = [1|L], dif:dif([1|L],B). % Either this
L = [1|L], dif:dif([1|[1|[1|...]],B). % or this
Also, it is still working as expected. I suspect this may be just an attribute_goals//1
issue:
?- L = [1|L], dif(L, B), B = [1|B].
false. % Expected
?- L = [1|L], dif(L, B), B = [1|1].
L = [1|L], B = [1|1]. % Expected
It is a toplevel issue only
?- L=[1|L],freeze(V,p(L)).
L = [1|L], freeze:freeze(V,user:p([1|1])).
?- L=[1|L],freeze(V,p(L)),copy_term(V,_,Gs).
L = [1|L], Gs = [freeze:freeze(_A,user:p([1|1]))], freeze:freeze(V,user:p([1|1])).
?- L=[1|L],freeze(V,p(L)),copy_term(V,_,Gs),acyclic_term(Gs).
false.
So Gs remains cyclic.
@UWN another example of swapping arguments:
?- L=[L|1],dif(B,L).
L = [L|1], dif:dif(B,[1|1]).
?- L=[L|1],dif(L,B).
L = [L|1], dif:dif([1|1],[1|1]).