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

Odd dif/2 residual with cyclic list

Open infradig opened this issue 1 year ago • 4 comments

$ scryer-prolog ?- L=[1|L], dif(L, B). L = [1|L], dif:dif([1|1],B). ?-

infradig avatar Jan 10 '24 12:01 infradig

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.

UWN avatar Jan 10 '24 13:01 UWN

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

bakaq avatar Jan 10 '24 17:01 bakaq

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 avatar Jan 10 '24 18:01 UWN

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

flexoron avatar Jan 11 '24 18:01 flexoron