Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top level: infinite list represented incorrectly #2666

Open
UWN opened this issue Nov 20, 2024 · 2 comments
Open

top level: infinite list represented incorrectly #2666

UWN opened this issue Nov 20, 2024 · 2 comments

Comments

@UWN
Copy link

UWN commented Nov 20, 2024

?- call_nth(select(E, Xs, Xs),2).
   Xs = [_A,E|E], unexpected.
?- call_nth(select(E, Xs, Xs),2), Xs = [a,e|e].
   false. % proof that above answer substitution is incorrect
?- call_nth(select(E, Xs, Xs),2), Xs = [_A|_B], _B=[E|_B].
   Xs = [_A,E|_B], _B = [E|_B]. % the actual, expected one
@flexoron
Copy link

flexoron commented Nov 22, 2024

$ scryer-prolog -f
?- use_module(library(iso_ext)).
?- use_module(library(lists)).
?- [_|X] = X, call_nth(select(_,Xs,Xs),3), Xs=X, Xs=[x|Z].   % narrow list down to 3 [x,x,x|...]
   X = [x|X], Xs = [x,x,x|x], Z = [x,x|x].                   % Xs=[x,x,x as expected but with issue |x].
?- [_|X] = X, call_nth(select(_,Xs,Xs),3), Xs=X, Xs=[x,x|Z]. % 2 or more [x,x,...|Z]
   X = [x|X], Xs = [x,x,x|Z], Z = [x|Z].                     % issue vanished.

Though

?- [_|X] = X, call_nth(select(_,Xs,Xs),3), Xs=X, Xs=[x,x|Z], write_term(Xs,[max_depth(8)]),nl.
[x,x,x|x] % issue revealed
   X = [x|X], Xs = [x,x,x|Z], Z = [x|Z].
?-

@vihaanjim
Copy link

?- X=[0|L], L=[0|L].
   X = [0,0|L], L = [0|L]. % correct
?- use_module(library(lambda)).
?- X+\ (X=[0|L], L=[0|L]).
   X = [0,0|0]. % incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants