* If Term is a variable, it is printed using write/1.
* If Term is a nonvariable or an attributed variable, then portray(output, Term) is called. If it succeeds, so does print/1. Otherwise, if Term is atomic, it is written using write/1 and the predicate succeeds. If Term is a compound term, its main functor is printed using write/1 and print/1 is called recursively on its arguments.
If portray/2 is not visible but portray/1 is, it is called instead of portray/2.
Note that when this predicate is used to print a list, only the elements of the list, i.e. the heads, are passed to the recursive calls of print/2, but not the list tails. Thus e.g. a list [1,2,3] will be passed once to portray/2 as a whole and then the elements 1, 2, 3, but not [2,3], [3] and [].
portray/1, 2 is used by the system when printing the answer bindings in the top-level loop, and by the debugger to print trace lines.
print(Term) is equivalent to write_term(Term, [portrayed(true), numbervars(true)]).
As usual, the output is buffered, so it may need to be flushed (e.g. explicitly using flush/1).
Note The output of print/1 is not necessarily in a form acceptable to read/1,2.
Success: ?- [user]. portray(S, a) :- write(S, b). user compiled 100 bytes in 0.02 seconds yes. ?- print([a, b, c, d]). [b, b, c, d] yes. ?- [user]. portray(S, '$VAR'(X)) :- write(S, 'X_'), write(S, X). user compiled 180 bytes in 0.00 seconds yes. ?- lib(numbervars). yes. ?- F=f(_,_,_,_), numbervars(F, 0, _), write(F). f(A, B, C, D) % default printing of '$VAR'/1 F = f(X_0, X_1, X_2, X_3) % toplevel uses portray yes.