This predicate subsumes all other output predicates, and it also offers formatted printing. Its syntax is similar to the C printf(3) function, but it also has further Prolog-specific options. For example, the sequence
write('The result is '),
writeq(T),
write(', which is '),
write(P),
write('% better than '),
write(R),
nl,
flush(output).
can be written with
printf("The result is %q, which is %d%% better than %w\n%b", [T, P, R]).
In the printf/2,3 predicate, several options for printing Prolog terms
can be specified by using the following option characters in the %w
format string:
write(X) :- printf("%w", [X]).
writeq(X) :- printf("%QDTMvw", [X]).
print(X) :- printf("%Pw", [X]).
display(X) :- printf("%O.w", [X]).
write_canonical(X) :- printf("%O.QDTMvw", [X]).