![]() |
YAP 7.1.0
|
This file includes the definition of the formatted output predicates. More...
This file includes the definition of the formatted output predicates.
class format/2 |
format(+ T, :L)
format(+_Stream_+ T, :ListWithArguments)
format(+ T, :ListWithArguments)
Print formatted output to the current output stream The arguments in list L are output according to the string, list of codes or characters, or by the atom T
A control sequence is introduced by a ~
The following control sequences are available in YAP:
~~
Print a single tilde~a
The next argument must be an atom, that will be printed as if by write
~Nc
The next argument must be an integer, that will be printed as a character code The number N is the number of times to print the character (default 1)~Ne
~NE
~Nf
~Ng
~NG
The next argument must be a floating point number The float F, the number N and the control code c
will be passed to printf
as:As an example:
~Nd
The next argument must be an integer, and N is the number of digits after the decimal point If N is 0
no decimal points will be printed The default is N = 0~ND
Identical to ~Nd
, except that commas are used to separate groups of three digits~i
Ignore the next argument in the list of arguments:~k
Print the next argument with write_canonical
:~Nn
Print N newlines (where N defaults to 1)~NN
Print N newlines if at the beginning of the line (where N defaults to 1)~Nr
The next argument must be an integer, and N is interpreted as a radix, such that 2 <= N <= 36
(the default is 8)Note that the letters a-z
denote digits larger than 9
~NR
Similar to ~NR
The next argument must be an integer, and N is interpreted as a radix, such that 2 <= N <= 36
(the default is 8)The only difference is that letters A-Z
denote digits larger than 9
~p
Print the next argument with print/1 :~q
Print the next argument with writeq/1 :~Ns
The next argument must be a list of character codes.The system then outputs their representation as a string, where N is the maximum number of characters for the string ( N defaults to the length of the string)~w
Print the next argument with write/1 :~W
Give the next two arguments to write_term/2 The first is the term to print, and the second is a list of write_term/2 options For example:This option is SWI-Prolog specific
The number of arguments, N
, may be given as an integer, or it may be given as an extra argument The next example shows a small procedure to write a variable number of a
characters:
The format/2 built-in also allows for formatted output One can specify column boundaries and fill the intermediate space by a padding character:
~N|
Set a column boundary at position N, where N defaults to the current position~N+
Set a column boundary at N characters past the current position, where N defaults to 8
~Nt
Set padding for a column, where N is the fill code (default is SPC
)The next example shows how to align columns and padding We first show left-alignment:
Note that we reserve 16 characters for the column
The following example shows how to do right-alignment:
The ~t
escape sequence forces filling before Hello
We next show how to do centering:
The two ~t
escape sequence force filling both before and after Hello
Space is then evenly divided between the right and the left sides
~@
Evaluate the next argument as a goal whose standard output is directed to the stream used by format/2Print formatted output to the current output stream
Print formatted output to the stream Stream
class with_output_to/2 |
with_output_to(+ Ouput,: Goal)
Run Goal as once/1 , while characters written to the current output are sent to Output The predicate was introduced by SWI-Prolog
The example below defines the DCG rule term/3
to insert a term in the output:
#define TOO_FEW_ARGUMENTS | ( | Needs, | |
Has_Repeats | |||
) |
Macros | |
#define | TMP_STRING_SIZE 1024 |
#define | TOO_FEW_ARGUMENTS(Needs, Has_Repeats) |
Functions | |
void | Yap_InitFormat (void) |