~. For example,
format("~thello~t world~t~a~t~4c~t~4d~t~7f",[atom,0'x,123,12.3])
give the following output:
hello world atom xxxx 123 12.300000
The control characters ~a, ~4c,~4d, and ~7f control the output of the atom atom, character 0'x, integer 123, and float 12.3, respectively. The control characters ~t put the data into different columns.
The following control characters are supported:
~~: Print ~.
~N|: Specifies a new position for the next argument.
~N+: The same as ~N|.
~a: print the atom without quoting. Exception is raised if the argument is not an atom.
~Nc: The argument must be a character code. Output the argument N times. Output the argument once if N is missing.
~Nf,~Ne, ~Ng: The argument must be a number. The C function printf is called to print the argument with the format "%.Nf", "%.Ne", and "%.Ng", respectively. ".N'' does not occur in the format for the C function if N is not specified in the Prolog format.
~Nd: The argument must be a number. N specifies the width of the argument. If the argument occupies more than N spaces, then enough spaces are filled to the left of the number.
~Nr: The argument must be an integer. Print the integer as a base N integer where
~NR: The argument must be an integer. Print the integer as a base N integer where
~Ns: The argument must be a list of character codes. Exactly N characters will be printed. Spaces are filled to the right of the string if the length of the string is less than N.
~k: Pass the argument to write_canonical/1.
~p: Pass the argument to print/1.
~q: Pass the argument to writeq/1.
~w: Pass the argument to write/1.
~Nn: Print N new lines.
~t: Move the position to the next column. Each column is assumed to be 8 characters long.
~@: Interpret the next argument as a goal and execute it.
Neng-Fa Zhou 2012-01-03