OCaml library : Printf (original) (raw)

Module Printf

module Printf: sig .. end

Formatted output functions.


val fprintf : [out_channel](Stdlib.html#TYPEout%5Fchannel) -> ('a, [out_channel](Stdlib.html#TYPEout%5Fchannel), unit) [format](Stdlib.html#TYPEformat) -> 'a

fprintf outchan format arg1 ... argN formats the argumentsarg1 to argN according to the format string format, and outputs the resulting string on the channel outchan.

The format string is a character string which contains two types of objects: plain characters, which are simply copied to the output channel, and conversion specifications, each of which causes conversion and printing of arguments.

Conversion specifications have the following form:

% [flags] [width] [.precision] type

In short, a conversion specification consists in the % character, followed by optional modifiers and a type which is made of one or two characters.

The types and their meanings are:

The optional flags are:

The optional width is an integer indicating the minimal width of the result. For instance, %6d prints an integer, prefixing it with spaces to fill at least 6 characters.

The optional precision is a dot . followed by an integer indicating how many digits follow the decimal point in the %f,%e, %E, %h, and %H conversions or the maximum number of significant digits to appear for the %F, %g and %G conversions. For instance, %.4f prints a float with 4 fractional digits.

The integer in a width or precision can also be specified as*, in which case an extra integer argument is taken to specify the corresponding width or precision. This integer argument precedes immediately the argument to print. For instance, %.*f prints a float with as many fractional digits as the value of the argument given before the float.

val printf : ('a, [out_channel](Stdlib.html#TYPEout%5Fchannel), unit) [format](Stdlib.html#TYPEformat) -> 'a

val eprintf : ('a, [out_channel](Stdlib.html#TYPEout%5Fchannel), unit) [format](Stdlib.html#TYPEformat) -> 'a

val sprintf : ('a, unit, string) [format](Stdlib.html#TYPEformat) -> 'a

Same as Printf.fprintf, but instead of printing on an output channel, return a string containing the result of formatting the arguments.

val bprintf : [Buffer.t](Buffer.html#TYPEt) -> ('a, [Buffer.t](Buffer.html#TYPEt), unit) [format](Stdlib.html#TYPEformat) -> 'a

Same as Printf.fprintf, but instead of printing on an output channel, append the formatted arguments to the given extensible buffer (see module Buffer).

val ifprintf : 'b -> ('a, 'b, 'c, unit) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as Printf.fprintf, but does not print anything. Useful to ignore some material when conditionally printing.

val ibprintf : [Buffer.t](Buffer.html#TYPEt) -> ('a, [Buffer.t](Buffer.html#TYPEt), unit) [format](Stdlib.html#TYPEformat) -> 'a

Same as Printf.bprintf, but does not print anything. Useful to ignore some material when conditionally printing.

Formatted output functions with continuations.

val kfprintf : ([out_channel](Stdlib.html#TYPEout%5Fchannel) -> 'd) -> [out_channel](Stdlib.html#TYPEout%5Fchannel) -> ('a, [out_channel](Stdlib.html#TYPEout%5Fchannel), unit, 'd) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as fprintf, but instead of returning immediately, passes the out channel to its first argument at the end of printing.

val ikfprintf : ('b -> 'd) -> 'b -> ('a, 'b, 'c, 'd) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as kfprintf above, but does not print anything. Useful to ignore some material when conditionally printing.

val ksprintf : (string -> 'd) -> ('a, unit, string, 'd) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as sprintf above, but instead of returning the string, passes it to the first argument.

val kbprintf : ([Buffer.t](Buffer.html#TYPEt) -> 'd) -> [Buffer.t](Buffer.html#TYPEt) -> ('a, [Buffer.t](Buffer.html#TYPEt), unit, 'd) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as bprintf, but instead of returning immediately, passes the buffer to its first argument at the end of printing.

val ikbprintf : ([Buffer.t](Buffer.html#TYPEt) -> 'd) -> [Buffer.t](Buffer.html#TYPEt) -> ('a, [Buffer.t](Buffer.html#TYPEt), unit, 'd) [format4](Stdlib.html#TYPEformat4) -> 'a

Same as kbprintf above, but does not print anything. Useful to ignore some material when conditionally printing.

Deprecated

val kprintf : (string -> 'b) -> ('a, unit, string, 'b) [format4](Stdlib.html#TYPEformat4) -> 'a

Deprecated. Use Printf.ksprintf instead.

A deprecated synonym for ksprintf.