format/[2,3]
format(
+Control,
+Arguments)
format(
+Stream,
+Control,
+Arguments)
Interprets the Arguments according to the Control string and prints the result on Stream.
Defaults to the current output stream.
A string, which can contain control sequences of the form `~<n><c>':
Any characters that are not part of a control sequence are written
to the specified output stream.
List of arguments, which will be interpreted and possibly printed by format control options.
If <n> can be specified, then it can be the character `*'. In this case <n> will be taken as the next argument from Arguments.
The following control options cause formatted printing of the next element from Arguments to the current output stream.
The intuition is that for numbers like 123000000.0, at most N consecutive zeroes before the decimal point are allowed in `f' notation. Similarly for numbers like 0.000000123.
`E' notation is forced by using `~-1H'.
`F' is forced by using `~999H'.
write_canonical/1
(see ref-iou-tou).
print/1
(see ref-iou-tou).
writeq/1
(see ref-iou-tou).
write/1
(see ref-iou-tou).
\+ \+
Arg
and is expected to print on the current output stream. If the goal
performs other side-effects, the behavior is undefined.
The following control sequences set column boundaries and specify padding. A column is defined as the available space between two consecutive column boundaries on the same line. A boundary is initially assumed at line position 0. The specifications only apply to the line currently being written.
When a column boundary is set (`~|' or `~+') and there are fewer characters written in the column than its specified width, the remaining space is divided equally amongst the pad sequences (`~t') in the column. If there are no pad sequences, the column is space padded at the end.
If `~|' or `~+' specifies a position preceding the current position, the boundary is set at the current position.
`
C where C is
the fill character. The default fill character is <SPC>. Any
(`~t') after the last column boundary on a line is ignored.
Stream errors (see ref-iou-sfh-est), plus:
consistency_error
| ?- Pi=3.14159265, format('~e ~2E ~0E\n', [Pi,Pi,Pi]). 3.141593e+00 3.14E+00 3.0E+00
| ?- Pi=3.14159265, format('~f, ~2F, ~0F\n', [Pi,Pi,Pi]). 3.141593, 3.14, 3.0
| ?- format('~g ~2G ~0G\n', [1.23456789e+10, 3.14159265, 0.0123]). 1.23457e+10 3.1 0.01
| ?- F = 123000.0, G = 0.000123, format('~h ~h ~2h ~2H ~-1H\n', [F,G,F,G,3.14]). 123000.0 0.000123 1.23e+05 1.23E-04 3.14E+00
| ?- format('Hello ~1d world!\n', [42]). Hello 4.2 world! | ?- format('Hello ~d world!\n', [42]). Hello 42 world!
| ?- format('Hello ~1D world!\n', [12345]). Hello 1,234.5 world!
| ?- format('Hello ~2r world!\n', [15]). Hello 1111 world! | ?- format('Hello ~16r world!\n', [15]). Hello f world!
| ?- format('Hello ~16R world!\n', [15]). Hello F world!
| ?- format('Hello ~4s ~4s!\n', ["new","world"]). Hello new worl! | ?- format('Hello ~s world!\n', ["new"]). Hello new world!
| ?- format('Hello ~i~s world!\n', ["old","new"]). Hello new world!
| ?- format('Hello ~k world!\n', [[a,b,c]]). Hello .(a,.(b,.(c,[]))) world!
| ?- assert((portray([X|Y]) :- print(cons(X,Y)))). | ?- format('Hello ~p world!\n', [[a,b,c]]). Hello cons(a,cons(b,cons(c,[]))) world!
| ?- format('Hello ~q world!\n', [['A','B']]). Hello ['A','B'] world!
| ?- format('Hello ~w world!\n', [['A','B']]). Hello [A,B] world!
| ?- format('Hello ~@ world!\n', [write(new)]). Hello new world!
| ?- format('Hello ~~ world!\n', []). Hello ~ world!
| ?- format('Hello ~n world!\n', []). Hello world!
| ?- format('~`*t NICE TABLE ~`*t~61|~n', []), format('*~t*~61|~n', []), format('*~t~a~20|~t~a~t~20+~a~t~20+~t*~61|~n', ['Right aligned','Centered','Left aligned']), format('*~t~d~20|~t~d~t~20+~d~t~20+~t*~61|~n', [123,45,678]), format('*~t~d~20|~t~d~t~20+~d~t~20+~t*~61|~n', [1,2345,6789]), format('~`*t~61|~n', []).
************************ NICE TABLE ************************* * * * Right aligned Centered Left aligned * * 123 45 678 * * 1 2345 6789 * *************************************************************
| ?- format('Table of Contents ~t ~a~72|~*n', [i,3]), format('~tTable of Contents~t~72|~*n', 2), format("1. Documentation supplement for ~s~1f \c ~`.t ~d~72|~*n", ["Quintus Prolog Release ",1.5,2,2]), format("~t~*+~w Definition of the term \"loaded\" \c ~`.t ~d~72|~n", [3,1-1,2]), format("~t~*+~w Finding all solutions ~`.t ~d~72|~n", [3,1-2,3]), format("~t~*+~w Searching for a file in a library \c ~`.t ~d~72|~n", [3,1-3,4]), format("~t~*+~w New Built-in Predicates ~`.t ~d~72|~n", [3,1-4,5]), format("~t~*+~w write_canonical (?Term) ~`.t ~d~72|~n", [7,1-4-1,5]), format("~*+.~n~*+.~n~*+.~n", [20,20,20]), format("~t~*+~w File Specifications ~`.t ~d~72|~n", [3,1-7,17]), format("~t~*+~w multifile(+PredSpec) ~`.t ~d~72|~n", [7,1-7-1,18]).
Table of Contents 1. Documentation supplement for Quintus Prolog Release 1.5 ........... 2 1-1 Definition of the term "loaded" ............................... 2 1-2 Finding all solutions ......................................... 3 1-3 Searching for a file in a library ............................. 4 1-4 New Built-in Predicates ....................................... 5 1-4-1 write_canonical (?Term) ................................. 5 . . . 1-7 File Specifications .......................................... 17 1-7-1 multifile(+PredSpec) ................................... 18