~
. For example,
format("~thello~t world~t~a~t~4c~t~4d~t~7f",[atom,0'x,123,12.3])gives the following output:
hello world atom xxxx 123 12.300000The control characters
~a
, ~4c
,~4d
, and ~7f
control the output of the atom atom, the character 0'x
, the integer 123, and the float 12.3, respectively. The control characters ~t
put the data into different columns.
The following control characters are supported:
~~
: Prints ~
.
~N|
: Specifies a new position for the next argument.
~N+
: This is the same as ~N|
.
~a
: Prints the atom without quoting. An exception is raised if the argument is not an atom.
~Nc
: The argument must be a character code. Outputs the argument N times. Outputs 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. Prints the integer as a base N integer, where
~NR
: The argument must be an integer. Prints 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
: Passes the argument to write_canonical/1.
~p
: Passes the argument to print/1.
~q
: Passes the argument to writeq/1.
~w
: Passes the argument to write/1.
~Nn
: Prints N new lines.
~t
: Moves the position to the next column. Each column is assumed to be 8 characters long.
~@
: Interprets the next argument as a goal, and executes it.
Neng-Fa Zhou 2013-01-25