File "format"

This Prolog text provides formatting of terms and numbers. The formatter format/[2,3] will delegate formatting of evaluable expressions via ~Ne, ~Nf and ~Ng to atom_number/4 and via ~d and ~Nr to atom_integer/3. Formatting of terms via ~k, ~q and ~w calls the corresponding 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 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: Formatted in atom xml escape format.
~c: Formatted in atom percent encode format.
~d: Formatted in integer decimal number format.
~Ne: Formatted in float exponential number format, N defaults to 6.
~Nf: Formatted in float fixed number format, N defaults to 6.
~Ng: Formatted in float general number format, N defaults to 6.
~k: Formatted with write_canonical/2 predicate.
~n: Emit the new line character.
~q: Formatted with writeq/2 predicate.
~Nr: Formatted in integer radix number format, N defaults to 8.
~w: Formatted with write/2 predicate.
~~: 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.
atom_number(A, S, N, F):
The built-in succeeds in A with the number F formatted according to the format specifier S and the number of digits N. The following format specifiers are supported:

e: Formatted in exponential number format.
f: Formatted in fixed number format.
g: Formatted in fixed number format.

Kommentare