Go to the first, previous, next, last section, table of contents.


Formatted output

Version: 1.5#118 (2000/4/19, 18:13:43 CEST)

Version of last change: 1.3#27 (1999/7/9, 20:25:50 MEST)

The format family of predicates is due to Quintus Prolog. They act as a Prolog interface to the C stdio function printf(), allowing formatted output.

Output is formatted according to an output pattern which can have either a format control sequence or any other character, which will appear verbatim in the output. Control sequences act as place-holders for the actual terms that will be output. Thus

        | ?- format("Hello ~q!",world).

will print Hello world!.

If there is only one item to print it may be supplied alone. If there are more they have to be given as a list. If there are none then an empty list should be supplied. There has to be as many items as control characters.

The character ~ introduces a control sequence. To print a ~ verbatim just repeat it:

        | ?- format("Hello ~~world!", []).

will result in Hello ~world!.

A format may be spread over several lines. The control sequence followed by a LFD will translate to the empty string:

        | ?- format("Hello world!", []).

will result in Hello world!.

Usage and interface (format)

Documentation on exports (format)

PREDICATE: format/2:

Usage: format(Format,Arguments)

PREDICATE: format/3:

Usage: format(+Stream,Format,Arguments)

REGTYPE: format_control/1:

The general format of a control sequence is ~NC. The character C determines the type of the control sequence. N is an optional numeric argument. An alternative form of N is *. * implies that the next argument in Arguments should be used as a numeric argument in the control sequence. Example:

| ?- format("Hello~4cworld!", [0'x]).

and

| ?- format("Hello~*cworld!", [4,0'x]).

both produce

Helloxxxxworld!

The following control sequences are available.

The following control sequences are also available for compatibility, but do not perform any useful functions.

Usage: format_control(C)


Go to the first, previous, next, last section, table of contents.