4 (export format get-output-string open-output-string)
6 (import (primitives format open-output-string get-output-string))
9 ;; Copyright 1998 Lars T Hansen.
12 ;; (format <port> <format-string> <arg> ...)
14 ;; <port> can be: an output port
15 ;; #t, denoting (current-output-port)
16 ;; #f, denoting an output string (that is returned)
18 ;; The following formatting characters are valid:
19 ;; ~a - write as with 'display'
20 ;; ~b - write bytevector elements (decimal)
21 ;; ~B - write bytevector elements (hexadecimal)
22 ;; ~c - write character as with 'write-char'
23 ;; ~f - write number as with 'display', though see below
24 ;; ~x - write integer in base 16
25 ;; ~o - write integer in base 8
26 ;; ~s - write as with 'write', compatible with Chez Scheme
27 ;; ~w - write as with 'write'
28 ;; ~? - next two args are another format string and a list of
29 ;; arguments, respectively;; recursively invoke format on
34 ;; ~a and ~w admit a field width specifier
35 ;; - an integer n formats the datum left-justified in a field that
36 ;; is at least n characters wide, inserting spaces on the right
38 ;; - an integer n followed by @ formats the datum right-justified,
41 ;; ~f admits a formatting specifier
42 ;; - integers w and d, comma separated, that format the datum
43 ;; left justified in a field at least w characters wide rounded
44 ;; to d decimal places. w is optional in which case no leading
45 ;; spaces are printed;; ,d is optional in which case the number
46 ;; is formatted as with number->string and an attempt is made to
47 ;; fit it in the field (FIXME: should probably round it to fit,
48 ;; if that's possible.)