format

Many Scheme implementations have more-or-less a subset of CommonLisp's format function, but there're wide variations in detail.

[procedure] format output format-spec obj ...

ChezScheme: supports all of the Common Lisp format directives except for those specific to the Common Lisp pretty printer.

Chicken: implements almost complete spec of CommonLisp's format function in the module format.

There is a format in extras, with only a few formatting directives. See also fprintf, printf, sprintf.

Example:

(use extras) 
(format #t "Example output ~a: ~a~%" 1 20)

=> Example output 1: 20

SLIB: implements almost complete spec of CommonLisp's format function.

Gauche: output may be a port, #t, or #f. Recognizes ~s, ~a, ~d, ~b, ~o, ~x. Recognizes formatting parameters compatible to CommonLisp. output can be omitted.

STk: output may be a port, #t or #f. Recognizes ~s, ~a, without any formatting parameters.

SRFI-48: output may be a port, #t or #f. Recognizes ~s, ~a, ~w, ~d, ~x, ~o, ~b, ~c, ~y, ~?, ~k, ~f, ~~, ~%, ~t, ~&, ~_, ~h. ~f recognizes formatting parameters. ouptut can be omitted.

[procedure] format format-spec obj ...

SRFI-28: returns a formatted string. ~a, ~s, ~% and ~~ is defined. SRFI-29 adds ~@*.

Supported Fomat Directives

~H ~A ~S ~W ~~ ~T ~% ~& ~D ~X ~O ~B ~F ~C ~_ ~Y ~? ~K ~!
ChezScheme x @ @ @ @ @ @ @ @ @ @ @ @ @ x x @ x x
Chicken x o o x o x o x x o o o x o x x o x o
Gauche x @ @ x o x o x @ @ @ @ x x x x x x x
SLIB x @ @ x @ @ @ @ @ @ @ @ @ @ @ @ @ o o
SRFI-28 x o o x o x o x x x x x x x x x x x x
SRFI-48 o o o o o o o o o o o o @ o o o o o o
STk x o o x x x o x x x x x x x x x x x x
STklos o o o o o o o o o o o o @ o o o o o o
~I ~Q ~R ~P ~E ~G ~$ ~| ~^ ~/ ~* ~( ~) ~{ ~} ~[ ~; ~] ~<newline> ~< ~>
ChezScheme x x @ @ @ @ @ @ @ x @ @ @ @ @ @
Chicken x x x x x x x x x x x x x x o x
Gacuhe x x x x x x x x x x x x x x x x
SLIB o @ @ @ @ @ @ @ @ @ @ @ @ @ @ x
SRFI-28 x x x x x x x x x x x x x x x x
SRFI-48 x x x x x x x x x x x x x x x x
STk x x x x x x x x x x x x x x x x
STklos x x x x x x x x x x x x x x x x
  • o: supported
  • x: not supported
  • @: recognize format parameter

See Also

Library:Fmt: Alex Shinn's combinator formatting library.