I guess this is a small glitch in the Query Answer display:
/* SWI-Prolog 9.3.22 */
?- length(L,2), f(L) = R, S = [_A].
L = [_A, _B],
R = f([_A, _B]),
S = [_A].
The newly generated _A
and _B
are not checked whether
they already appear in the answer elsewhere, causing a name
clash. The more correct answer would be:
/* Scryer Prolog 0.9.4-403 */
?- length(L,2), f(L) = R, S = [_A].
L = [_B, _C],
R = f([_B, _C]),
S = [_A].
Other Prolog systems that avoid the clash as well are
Trealla Prolog, and since today Dogelog Player.
wlodr
May 26, 2025, 3:08pm
2
Old SICStus 4.5.1 behaves correctly.
herme
May 26, 2025, 3:21pm
3
This is what Ciao does for reference:
Ciao 1.24
?- length(L,2), f(L) = R, S = [_A].
L = [_B,_C],
R = f([_B,_C]),
S = [_] ?
herme:
This is what Ciao does for reference:
/* Ciao Prolog 1.24 */
?- length(L,2), f(L) = R, S = [_A].
L = [_B,_C],
R = f([_B,_C]),
S = [_] ?
Different Ciao Prolog inspired test case, expectation:
/* Trealla Prolog 2.71.33, Scryer Prolog 0.9.4-403 */
?- length(L,2), f(L) = R, S = [_A].
L = [_B, _C], R = f([_B, _C]), S = [_A].
/* SWI-Prolog 9.3.22 */
?- length(L,2), f(L) = R, S = [_].
L = [_A, _B], R = f([_A, _B]), S = [_].
Reality:
/* Trealla Prolog 2.71.33, Scryer Prolog 0.9.4-403 */
?- length(L,2), f(L) = R, S = [_].
L = [_A,_B], R = f([_A,_B]), S = [_C].
It seems that _
is not reconstructed.
jan
May 27, 2025, 8:35am
5
In a sense it is correct as we first remove all _X
variables from the answer But, I agree it is highly confusing. Pushed 18147fa7cc7ed63f2ef2ebfa4b8f5149385b42f0 to both reserve variables from the original query and generated variables, e.g., for breaking cycles, etc.
1 Like
The clash detection works in listing/1, I didn’t find an issue so
far. Take this example, one needs to put it into a file case.pl:
test --> p, {q(A,A)}, r.
SWI-Prolog then preserves the variable A
, but also
avoids a clash in the newly generated variables:
?- [case].
?- listing(test).
test(B, C) :-
p(B, D),
q(A, A),
E=D,
r(E, C).