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

'$skip_max_list'/4 issue #2688

Open
notoria opened this issue Dec 8, 2024 · 3 comments
Open

'$skip_max_list'/4 issue #2688

notoria opened this issue Dec 8, 2024 · 3 comments

Comments

@notoria
Copy link
Contributor

notoria commented Dec 8, 2024

?- [user].
:- use_module(library(between)).

sml(S, M, Xs0, Xs) :- '$skip_max_list'(S, M, Xs0, Xs).

query :-
   between(0, 9, M),
   Es = [0,1,2|Es],
   sml(S, M, Es, Fs),
   write_term(user_output, [S,M,Es,Fs], [variable_names(['Es'=Es,'Fs'=Fs])]), nl,
   false.

?- query.
% Warning: couldn't append history (existing file)
[0,0,[0,1,2|Es],[0,1,2|Es]]
[1,1,[0,1,2|Es],[1,2,0|Fs]]
[2,2,[0,1,2|Es],[2,0,1|Fs]]
[3,3,[0,1,2|Es],[0,1,2|Es]]
[4,4,[0,1,2|Es],[1,2,0|Fs]] % unexpected 4
[5,5,[0,1,2|Es],[2,0,1|Fs]] % unexpected 5
[3,6,[0,1,2|Es],[0,1,2|Es]]
[3,7,[0,1,2|Es],[0,1,2|Es]]
[3,8,[0,1,2|Es],[0,1,2|Es]]
[3,9,[0,1,2|Es],[0,1,2|Es]]
   false.
?-
@UWN
Copy link

UWN commented Dec 8, 2024

First thing I do not understand: How can the variable name be written out that way? What do we see there?? The variable Es is instantiated to a non-variable term so how does it show now in the output?

@notoria
Copy link
Contributor Author

notoria commented Dec 8, 2024

I remember now why the skip can be bigger than lambda+mu, it's for efficiency reason.

But:

?- length(Es0, 6), Es = [0,1,2|Es], nth0(N, Es, E, Fs), append(Es0, _, Fs).
   Es0 = [1,2,0,1,2,0], Es = [0,1,2|Es], N = 0, E = 0, Fs = [1,2,0|Fs]
;  Es0 = [0,2,0,1,2,0], Es = [0,1,2|Es], N = 1, E = 1, Fs = [0,2,0,1|2]
;  Es0 = [0,1,0,1,2,0], Es = [0,1,2|Es], N = 2, E = 2, Fs = [0,1,0,1,2|Es]
;  Es0 = [0,1,2,1,2,0], Es = [0,1,2|Es], N = 3, E = 0, Fs = [0,1,2,1,2,0|1]
;  Es0 = [0,1,2,0,2,0], Es = [0,1,2|Es], N = 4, E = 1, Fs = [0,1,2,0,2,0,1|2]
;  Es0 = [0,1,2,0,1,0], Es = [0,1,2|Es], N = 5, E = 2, Fs = [0,1,2,0,1,0,1,2|Es]
;  Es0 = [0,1,2,0,1,2], Es = [0,1,2|Es], N = 6, E = 0, Fs = [0,1,2,0,1,2,1,2,0|1]

The predicate nth0/4 has an issue. The value of Es0 should rotate.

The option variable_names is a bit permissive:

?- Es = [0,1,2|Es], write_term(user_output, A=Es, [variable_names(['Es'=A,'B'=Es,'C'=0])]), nl.
Es=[0,1,2|B]
   Es = [0,1,2|Es].
?-

A new option cycle_names could be created for cyclic term.

@UWN
Copy link

UWN commented Dec 9, 2024

..., [0,2,0,1|2]

A max_depth writing would really be preferable.

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

2 participants