File "format"

This Prolog text provides formatting of terms and numbers. The formatter format/[2,3] will delegate formatting of evaluable expressions via ~efg to half even rounded native formatting and via ~r to native base formatting. Formatting of numbers and terms calls the write predicates and directly writes into the given stream or current output.

Example:
?- format('abc ~4f def~n',[2*pi]).
abc 6.2832 def

The streaming behaviour is only suspended when a rubber band ~t is encountered. The subsequent formatting then buffered and later spread out. Further if the stream has the coloring flag set, the ~defgq format specifiers will do coloring. If the stream has the cyclic flag set, the ~q format specifier will do cyclic term detection.

The following format predicates are provided:

tab(N):
tab(S, N):
The predicate succeeds. As side effect N spaces are written to the current output. The binary predicate allows specifying the output stream.
format(T, L):
format(S, T, L):
The built-in succeeds in outputting the list L formatted according to the template T. The ternary predicate allows specifying an output stream. The following format controls are supported:

~a: Format in atom xml escape format.
~c: Format in atom percent encode format.
~d: Evaluated and format via write/2.
~Ne, ~NE: Evaluate and format in exponential N digits, N defaults to 6.
~Nf, ~NF: Evaluate and format in fixed N digits, N defaults to 6.
~Ng, ~NG: Evaluate and format in general N digits, N defaults to 6.
~Nr, ~NR: Evaluate and format in N radix, N defaults to 8.
~k: Format via write_canonical/2.
~q: Format via writeq/2.
~w: Format via write/2.
~N|: Emit spaces to reach the offset N, N defaults to 0.
~`Ct: Emit the character C to spread formatting, C defaults to ‘ ‘.
~n: Emit the new line character.
~~: Emit the character ~.
format_atom(T, L, A):
The build-in succeeds in writing the list L formatted according to the template T into a new atom A.


Use Privacy (c) 2005-2026 XLOG Technologies AG