Did SWI-Prologs underscore policy vanish?

Just noticed that this doesn’t work anymore,
using an underscore variable to suppresss showing
an answer substitution:

/* SWI-Prolog 9.1.17 */
?- findall(X, between(1,100,X), _L), R = foo.
_L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
R = foo.

/* GNU Prolog 1.5.0 */
?- findall(X, between(1,100,X), _L), R = foo.
R = foo

Expectation is rather that SWI-Prolog doesn’t show
the _L substitution. Is this a bug or freature?

It never worked by default. You need to opt-in using

?- set_prolog_flag(toplevel_print_anon, false).

Maybe you changed machine and didn’t copy the personal init.pl file?

From 5 tested systems, 3 seem to suppress _Var in default configuration. Possibly SWI-Prolog should change the default?

Does SWI-Prolog have a policy that works with all bells and whistles,
like the rational term printing. What are the test cases?

For example not sure whether this is a bug or feature:

/* SWI-Prolog 9.1.17 */
?- _L = [a|_L], R = [b|_L].
_L = [a|_L],
R = [b|_L].

?- set_prolog_flag(toplevel_print_anon, false).
true.

?- _L = [a|_L], R = [b|_L].
R = [b|_L].

We don’t know anymore what R is.

Neither do I :slight_smile: All choices have pros and cons. If you want to know , don’t start the variable with an underscore. That is at least a simple rule and flexible enough to get what you want. I think I consider the above a feature.

Interestingly SWI-Prolog sometimes prefers a longer representation,
for common Prolog terms among answer substitutions:

/* SWI-Prolog 9.1.17 */
?- L = [a,b|L].
L = [a, b|L].

?- R = [a,b,a,b|R].
R = [a, b, a, b|R].

?- L = [a,b|L], R = [a,b,a,b|R].
L = R, R = [a, b, a, b|R].

But then we might ask whether this is a bug or feature,
some spill over from a kind of unrelated term:

/* SWI-Prolog 9.1.17 */
?- set_prolog_flag(toplevel_print_anon, false).
true.

?- L = [a,b|L], _R = [a,b,a,b|_R].
L = [a, b, a, b|_R].

L is suddenty related to _R, although the Prolog term L was
only defined in terms of the Prolog term L itself.

1 Like