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


Formatted output

Author(s): The CLIP Group.

Version: 1.11#222 (2004/5/24, 13:8:7 CEST)

Version of last change: 1.11#89 (2003/12/21, 2:17:58 CET)

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 \c followed by a LFD will translate to the empty string:

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

will result in Hello world!.

Usage and interface (format)

Documentation on exports (format)

PREDICATE: format/2:

General properties: format(C, A)

Usage: format(format_control(Format), Arguments)

PREDICATE: format/3:

General properties: format(S, C, A)

Usage: format(Stream, format_control(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.