You are looking at historical revision 584 of this page. It may differ significantly from its current revision.


Code to generate format functions. It is relatively flexible, supporting inheritance and allowing you to extend your formatters. It is accompanied by an implementation of Common Lisp's format function which is thread safe and extendible (meaning you could define new format characters).

Note: This might be outdated!





[procedure] (make-format-function case-sensitive escape formatters)

Create and return a procedure that can be used as a format function. The resulting procedure receives a port, a format string and optional arguments. It parses the format string according to the formatters parameter and outputs a result to the port specified. If, instead of a port, #t is specified, the results will be sent to the current output port. If, on the other hand, #f is passed, the procedure will store its output on a new string and return it.

The returned procedure parses the format string looking for occurrences of the escape character (usually #\~); when one is found, a function from the formatters argument is called.

formatters is a list of formatters. Each formatter is itself a list of (char function) pairs, where char is the character for the escape sequence being defined and function the function to call when the character, preceeded by escape, is found in the format string.

To produce the functions included in the formatters, use (formatter-function proc), where proc is a procedure that receives the following parameters:

A structure with internal information. You won't normally inspect this directly but rather pass it to other functions that require it (such as out-char and out-string).
The position in the format string where the escape sequence was found. You'll normally just ignore this.
A list with paramters that occur between escape and char (for example, in a format string such as ~23,33,12A).
colon, atsign
Booleans indicating whether those characters occur between escape and char.

To output info at the current position, the formatter functions should use the out-char and out-string functions. The receive the state parameter (as passed to the formatter) and a character and string respectively.


[procedure] (format port fmtstring . args)