[Up] [Contents] [Index] [Summary]

3.30.2 Format

format(+Format)
Defined as `format(Format) :- format(Format, []).'

format(+Format, +Arguments)
Format is an atom, list of ASCII values, or a Prolog string. Arguments provides the arguments required by the format specification. If only one argument is required and this is not a list of ASCII values the argument need not be put in a list. Otherwise the arguments are put in a list.

Special sequences start with the tilde (~), followed by an optional numeric argument, followed by a character describing the action to be undertaken. A numeric argument is either a sequence of digits, representing a positive decimal number, a sequence `<character>, representing the ASCII value of the character (only useful for ~t) or a asterisk (*), in when the numeric argument is taken from the next argument of the argument list, which should be a positive integer. Actions are:

Example:

simple_statistics :- <obtain statistics> % left to the user format('~tStatistics~t~72|~n~n'), format('Runtime: ~`.t ~2f~34| Inferences: ~`.t ~D~72|~n', [RunT, Inf]), ....

Will output

Statistics Runtime: .................. 3.45 Inferences: .......... 60,345

format(+Stream, +Format, +Arguments)
As format/2, but write the output on the given Stream.

sformat(-String, +Format, +Arguments)
Equivalent to format/2, but ``writes'' the result on String instead of the current output stream. Example: ?- sformat(S, '~w~t~15|~w', ['Hello', 'World']). S = "Hello World"

sformat(-String, +Format)
Equivalent to `sformat(String, Format, []).'