Writes the objs to the given port, according to the format
string str. Str is written literally, except for the following
sequences:
~a or ~A is replaced by the printed representation
of the next obj.
~s or ~S is replaced by the "slashified" printed
representation of the next obj.
~w or ~W is replaced by the printed representation
of the next obj (circular structures are correctly handled and
printed using write*).
~d or ~D is replaced by the decimal printed representation
of the next obj (which must be a number).
~x or ~X is replaced by the hexadecimal printed representation
of the next obj (which must be a number).
~o or ~O is replaced by the octal printed representation
of the next obj (which must be a number).
~b or ~B is replaced by the binary printed representation
of the next obj (which must be a number).
~c or ~C is replaced by the printed representation
of the next obj (which must be a character).
~y or ~Y is replaced by the pretty-printed representation
of the next obj. The standard pretty-printer is used here.
~? is replaced by the result of the recursive call of format
with the two next obj.
~k or ~K is another name for ~?
~[w[,d]]f or ~[w[,d]]F is replaced by the printed
representation of next obj (which must be a number) with width w
and d digits after the decimal. Eventually, d may be omitted.
~~ is replaced by a single tilde character.
~% is replaced by a newline
~t or ~t is replaced by a tabulation character.
~& is replaced by a newline character if it is known that the
previous character was not a newline
~_ is replaced by a space
~h or ~H provides some help
Port can be a boolean or a port. If port is #t, output goes to
the current output port; if port is #f, the output is returned as a
string. Otherwise, the output is printed on the specified port.
(format #f "A test.") => "A test."
(format #f "A ~a." "test") => "A test."
(format #f "A ~s." "test") => "A \"test\"."
(format "~8,2F" 1/3) => " 0.33"
(format "~6F" 32) => " 32"
(format "~1,2F" 4321) => "4321.00"
(format "~1,2F" (sqrt -3.9)) => "0.00+1.97i"
(format "#d~d #x~x #o~o #b~b~%" 32 32 32 32)
=> "#d32 #x20 #o40 #b100000\n"
(format #f "~&1~&~&2~&~&~&3~%")
=> "1\n2\n3\n"
(format "~a ~? ~a" 'a "~s" '(new) 'test)
=> "a new test"
The second form of format is compliant with SRFI-28. That is, when
port is omitted, the output is returned as a string as if port was
given the value #f.
Since version 0.58, format is also compliant with SRFI-48.
|