2

I want to print the list of unbound variables to the screen.

12 ?- write([X, Y]).

[_G1696,_G1699]

But I want to see in fact [X, Y] on the screen instead of [_G1696,_G1699]. Is it possible? How?

Svetlana
  • 61
  • 6

1 Answers1

1

I assume that you want to pretty print terms with unbound variables? You can use the de facto standard numbervars/3 predicates to accomplish it. For example:

pretty_print_term(Stream, Term) :-
    \+ \+ (
        numbervars(Term, 0, _),
        write_term(Stream, Term, [numbervars(true)])).

pretty_print_term_quoted(Stream, Term) :-
    \+ \+ (
        numbervars(Term, 0, _),
        write_term(Stream, Term, [numbervars(true), quoted(true)])).

In these snippets, double negation is used to pretty print a term while discarding the instantiation of the variables by the numbervars/3 predicate.

An usage example:

?- current_output(Stream), pretty_print_term_quoted(Stream, [X, Y]).
[A,B]
Stream = <stream>(0x10bebcf18).
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33