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

Top level: incorrect display of some infinite terms

Open UWN opened this issue 1 year ago • 2 comments

(#2330 has nothing to do with dif/2)

?- freeze(V,T), [T|a]=T.
   T = [T|a], freeze:freeze(V,[a|a]), unexpected.
?- freeze(V,T), [T|a]=T, copy_term(V,VC,G_0s).
   T = [T|a], G_0s = [freeze:freeze(VC,[a|a]),a|a], freeze:freeze(V,[a|a]), unexpected.
?- freeze(V,T), [T|a]=T, copy_term(V,VC,[G_0s]).
   T = [T|a], G_0s = freeze:freeze(VC,[a|a]), freeze:freeze(V,[a|a]), unexpected.
?- freeze(V,T), [T|a]=T, copy_term(V,VC,[freeze:freeze(_,Fro)]).
   T = [T|a], Fro = [Fro|a], freeze:freeze(V,[a|a]).

The last shows clearly that the actual terms are fine as Fro is displayed correctly.

?- findall(I_0, ( freeze(V,T), [T|a]=T, copy_term(V,VC,[I_0]) ), [F_0]).
   F_0 = freeze:freeze(_A,[a|a]), unexpected.
?- findall(I_0, ( freeze(V,T), [T|a]=T, copy_term(V,VC,[I_0]) ), [F_0]), F_0 = freeze:freeze(Vx,Tx).
   F_0 = freeze:freeze(Vx,[Tx|a]), Tx = [Tx|a]. % expected!!

UWN avatar Feb 14 '24 12:02 UWN

This is seems to be a top level only issue:

f(F_0) :-
   findall(I_0, ( freeze(V,T), [T|a]=T, copy_term(V,_,[I_0]) ), [F_0]).

g(F_0,T):-F_0 = freeze:freeze(_,T).

?- f(F_0), g(F_0,T).
   F_0 = freeze:freeze(_A,[T|a]), T = [T|a].
?- f(F_0), g(F_0,_).
   F_0 = freeze:freeze(_A,[a|a]), unexpected.

UWN avatar Feb 14 '24 12:02 UWN

Shorter, the age of terms influences the outcome.

f(freeze(T)) :-
   [T|s]=T.

h(F_0) :-
   [T|s]=T,
   F_0 = freeze(T).

g(freeze(T),T).

?- f(T).
   T = freeze([s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,...|...]), unexpected.
?- h(T).
   T = freeze([s|s]), unexpected.
?- f(T),g(T,_).
   T = freeze([s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,...|...]), unexpected.
?- f(T),g(T,V).
   T = freeze([V|s]), V = [V|s].
?- h(T),g(T,V).
   T = freeze([V|s]), V = [V|s].

UWN avatar Feb 14 '24 13:02 UWN