Next: , Up: iklib printing   [Index]


6.39.1 Formatting and printing strings

Function: format template arg

Build and return a new string formatted according to the template in the string template and the supplied arguments. The template string contains markers in which the string representation of each argument is placed. The markers include:

~s

Instructs the formatter to place the next argument as if the procedure write has printed it; if the argument contains a string, the string will be quoted and all quotes and backslashes in the string will be escaped; similarly, characters will be printed using the #\x notation.

~a

Instructs the formatter to place the next argument as if the procedure display has printed it; strings and characters are placed as they are in the output.

~b

Instructs the formatter to convert the next argument to its binary (base 2) representation; the argument must be an exact number.

~o

Similar to ~b except that the number is printed in octal (base 8).

~x

Similar to ~b except that the number is printed in hexadecimal (base 16).

~d

Outputs the next argument, which can be an exact or inexact number, in its decimal (base 10) representation.

~~

Instructs the formatter to place a tilde character, ~, in the output without consuming an argument.

~%

Instructs the formatter to place a newline character in the output without consuming an argument.

Note that the #b, #o, and #x numeric prefixes are not added to the output when ~b, ~o, and ~x are used.

> (format "message: ~s, ~s, and ~s" 'symbol "string" #\c)
"message: symbol, \"string\", and #\\c"

> (format "message: ~a, ~a, and ~a" 'symbol "string" #\c)
"message: symbol, string, and c"
Function: printf template arg

Similar to format except that the output is sent to the current-output-port instead of being collected in a string.

> (let ([n (+ (expt 2 32) #b11001)])
    (printf "~d = #b~b = #x~x\n" n n n))
4294967321 = #b100000000000000000000000000011001 = #x100000019
Function: fprintf output-port template arg

Similar to printf except that the textual output port to which the output is sent is specified as the first argument.


Next: , Up: iklib printing   [Index]