# (lispkit format)

Library `(lispkit format)` provides an implementation of [Common Lisp's `format` procedure](https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node200.html#SECTION002633000000000000000) for LispKit. Procedure `format` can be used for creating formatted text using a format string similar to `printf`. The formatting formalism, though, is significantly more expressive, allowing users to display numbers in various formats (e.g. hex, binary, octal, roman numerals, natural language), applying conditional formatting, outputting text in a tabular format, iterating over data structures, and even applying `format` recursively to handle data that includes its own preferred formatting strings.

## Usage overview

In its most simple form, procedure `format` gets invoked with a *control string* followed by an arbitrary number of *arguments*. The *control string* consists of characters that are copied verbatim into the output as well as *formatting directives*. All formatting directives start with a tilde (`~`) and end with a single character identifying the type of the directive. Directives may also take prefix *parameters* written immediately after the tilde character, separated by comma as well as *modifiers* (see below for details).

For example, the call of `format` below injects two integer arguments into the control string via directive `~D` and returns the resulting string:

```scheme
(format "There are ~D warnings and ~D errors." 12 7)
⇒ "There are 12 warnings and 7 errors."
```

### Simple Directives

Here is a simple control string which injects a readable description of an argument via the directive `~A`: `"I received ~A as a response"`. Directive `~A` refers to a the *next argument* provided to `format` when compiling the formatted output:

```scheme
(format "I received ~A as a response" "nothing")
⇒ "I received nothing as a response"
(format "I received ~A as a response" "a long email")
⇒ "I received a long email as a response"
```

Directive `~A` may be given parameters to influence the formatted output. The first parameter of `~A`-directives defines the minimal length. If the length of the textual representation of the next argument is smaller than the minimal length, padding characters are inserted:

```scheme
(format "|Name: ~10A|Location: ~13A|" "Smith" "New York")
⇒ "|Name: Smith     |Location: New York     |"
(format "|Name: ~10A|Location: ~13A|" "Williams" "San Francisco")
⇒ "|Name: Williams  |Location: San Francisco|"
(format "|Name: ~10,,,'_@A|Location: ~13,,,'-A|" "Garcia" "Los Angeles")
⇒ "|Name: ____Garcia|Location: Los Angeles--|"
```

The third example above utilizes more than one parameter and, in one case, includes a `@` modifier. The directive `~13,,,'-A` defines the first and the fourth parameter. The second and third parameter are omitted and thus defaults are used. The fourth parameter defines the padding character. If character literals are used in the parameter list, they are prefixed with a quote `'`. The directive `~10,,,'_@A` includes an `@` modifier which will result in padding of the output on the left.

It is possible to inject a parameter from the list of arguments. The following examples show how parameter `v` is used to do this for formatting a floating-point number with a configurable number of fractional digits.

```scheme
(format "length = ~,vF" 2 pi)
⇒ "length = 3.14"
(format "length = ~,vF" 4 pi)
⇒ "length = 3.1416"
```

Here `v` is used as the second parameter of the fixed floating-point directive `~F`, indicating the number of fractional digits. It refers to the next provided argument (which is either 2 or 4 in the examples above).

### Composite Directives

The next example shows how one can refer to the total number of arguments that are not yet consumed in the formatting process by using `#` as a parameter value.

```scheme
(format "~A left for formatting: ~#[none~;one~;two~:;many~]."
        "Arguments" "eins" 2)
⇒ "Arguments left for formatting: two."
(format "~A left for formatting: ~#[none~;one~;two~:;many~]."
        "Arguments")
⇒ "Arguments left for formatting: none."
(format "~A left for formatting: ~#[none~;one~;two~:;many~]."
        "Arguments", "eins", 2, "drei", "vier")
⇒ "Arguments left for formatting: many."
```

In these examples, the *conditional directive* `~[` is used. It is followed by *clauses* separared by directive `~;` until `~]` is reached. Thus, there are four clauses in the example above: `none`, `one`, `two`, and `many`. The parameter in front of the `~[` directive determines which of the clauses is being output. All other clauses will be discarded. For instance, `~1[zero~;one~;two~:;many~]` will output `one` as clause 1 is chosen (which is the second one, given that numbering starts with zero). The last clause is special because it is prefixed with the `~;` directive using a `:` modifier: this is a *default clause* which is chosen when none of the others are applicable. Thus, `~8[zero~;one~;two~:;many~]` outputs `many`. This also explains how the example above works: here `#` refers to the number of arguments that are still available and this number drives what is being returned in this directive: `~#[...~]`.

Another powerful composite directive is the *iteration directive* `~{`. With this directive it is possible to iterate over all elements of a sequence. The control string between `~{` and `~}` gets repeated as long as there are still elements left in the sequence which is provided as an argument. For instance, `Numbers:~{ ~A~}` applied to argument `("one" "two" "three")` results in the output `Numbers: one two three`. The control string between `~{` and `~}` can also consume more than one element of the sequence. Thus, `Numbers:~{ ~A=>~A~}` applied to argument `("one" 1 "two" 2)` outputs `Numbers: one=>1 two=>2`.

Of course, it is also possible to nest arbitrary composite directives. Here is an example for a control string that uses a combination of iteration and conditional directives to output the elements of a sequence separated by a comma: `(~{~#[~;~A~:;~A, ~]~})`. When this control string is used with the argument `("one" "two" "three")`, the following formatted output is generated: `(one, two, three)`.

## Formatting language

*Control strings* consist of characters that are copied verbatim into the output as well as *formatting directives*. All formatting directives start with a tilde (`~`) and end with a single character identifying the type of the directive. Directives may take prefix *parameters* written immediately after the tilde character, separated by comma. Both integers and characters are allowed as parameters. They may be followed by formatting *modifiers* `:`, `@`, and `+`. This is the general format of a formatting directive:

```ebnf
~param1,param2,...mX
```

where

* `m` is a potentially empty modifier, consisting of an arbitrary sequence of modifier characters `:`, `@`, and `+`
* `X` is a character identifying a directive type
* `paramN` is either a nummeric or character parameter according to the specification below.

The following grammar describes the syntax of directives formally in BNF:

```ebnf
<directive>  ::= "~" <modifiers> <char>
               | "~" <parameters> <modifiers> <char>
<modifiers>  ::= <empty>
               | ":" <modifiers>
               | "@" <modifiers>
               | "+" <modifiers>
<parameters> ::= <parameter>
               | <parameter> "," <parameters>
<parameter>  ::= <empty>
               | "#"
               | "v"
               | <number>
               | "-" <number>
               | <character>
<number>     ::= <digit>
               | <digit> <number>
<digit>      ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<character>  ::= "'" <char>
```

## Formatting directives

The formatting directives supported by library `(lispkit format)` are based on the directives specified in [Common Lisp the Language, 2nd Edition](https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node1.html) by Guy L. Steele Jr. Some directives have been extended to meet today's formatting requirements (e.g. to support localization) and to enable a powerful usage throughout LispKit. Extensions were introduced in a way to not impact backward compatibility.

| Directive                                           | Explanation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | -------------------------- | ---------- | ---------------------------- | ------------------------ | -------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ------------------ | ---------- | ---------------------------------------------------- | -------------------- | ------------------ | ---------- | ---------------------------- | --------------------- | ------------------ | ---------- | ---------------------------------------------------- | --------------------- | ------------------ | ---------- | ---------------------------- | ---------------------- | ------------------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ---- | ---- | ---------------------------- | ------ | ---------- | ---------- | ------------------------------------------------- | ------- | --- | --- | ---------------------------- | ------ | ---------- | ---------- | ------------------------------------------------- | ------- | --------- | --------- | ----------- |
| <p><strong>\~a</strong><br><strong>\~A</strong></p> | <p>ASCII:  <strong>\~</strong><em><strong>mincol,colinc,minpad,padchar,maxcol,elchar</strong></em><strong>A</strong></p><p>The next argument <em>arg</em> is output as if procedure <code>display</code> was used, i.e. the output is without escape characters and if <em>arg</em> is a string, its characters will be output verbatim without surrounding quotes.</p><p><em>mincol</em> (default: 0) specifies the minimal "width" of the output of the directive in characters, <em>maxcol</em> (default: ∞) specifies the maximum width. <em>padchar</em> (default: ' ') defines the character that is used to pad the output to make sure it is at least <em>mincol</em> characters long. By default, the output is padded on the right with at least <em>minpad</em> (default: 0) copies of <em>padchar</em>. Padding characters are then inserted <em>colinc</em> (default: 1) characters at a time until the total width is at least <em>mincol</em>. Padding is capped such that the output never exceeds <em>maxcol</em> characters. If, without padding, the output is already longer than <em>maxcol</em>, the output is truncated at width <em>maxcol - 1</em> and the ellipsis character <em>elchar</em> (default: '…') is inserted at the end.</p><p>Modifier <code>@</code> enables padding on the left to right-align the output.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~w</strong><br><strong>\~W</strong></p> | <p>WRITE:  <strong>\~</strong><em><strong>mincol,colinc,minpad,padchar,maxcol,elchar</strong></em><strong>W</strong></p><p>The next argument <em>arg</em> is output as if procedure <code>write</code> was used, i.e. the output is with escape characters and if <em>arg</em> is a string, its characters will be output surrounded by quotes.</p><p>Parameters <em>mincol</em> (default: 0), <em>colinc</em> (default: 1), <em>minpad</em> (default: 0), <em>padchar</em> (default: ' '), <em>maxcol</em> (default: ∞), and <em>elchar</em> (default: '…') are used just as described for the <em>ASCII directive</em> <code>\~A</code>. Modifier <code>@</code> enables padding on the left to right-align the output.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~s</strong><br><strong>\~S</strong></p> | <p>SOURCE:  <strong>\~</strong><em><strong>mincol,colinc,minpad,padchar,maxcol,elchar</strong></em><strong>S</strong></p><p>The next argument <em>arg</em> is output using a type-specific control string. If no control string is registered for the type of <em>arg</em>, then <code>\~S</code> behaves like <code>\~W</code> for <em>arg</em>.</p><p>Parameters <em>mincol</em> (default: 0), <em>colinc</em> (default: 1), <em>minpad</em> (default: 0), <em>padchar</em> (default: ' '), <em>maxcol</em> (default: ∞), and <em>elchar</em> (default: '…') are used just as described for the <em>ASCII directive</em> <code>\~A</code>. Modifier <code>@</code> enables padding on the left to right-align the output.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~c</strong><br><strong>\~C</strong></p> | <p>CHARACTER:  <strong>~~C</strong></p><p>The next argument <em>arg</em> should be a character or a string consisting of one character. Directive <code>~~C</code> outputs <em>arg</em> in a form dependent on the modifiers used. Without any modifiers, <em>arg</em> is output as if the character was used in a string without any escaping.</p><p>If the <code>@</code> modifier is provided alone, the character is output using Scheme's syntax for character literals. The modifier combination <code>@:</code> will lead to <em>arg</em> being output as Unicode code points. The combination <code>@:+</code> will output <em>arg</em> as a sequence of Unicode scalar property names, separated by comma.</p><p>If the <code>:</code> modifier is used (without <code>@</code>), a representation of <em>arg</em> for the usage in XML documents is chosen. By default, a Unicode-based XML character encoding is used, unless <code>:</code> is combined with <code>+</code>, in which case the character is represented as a XML named character entity when possible, otherwise, the character is output in raw form.</p><p>If the <code>+</code> modifiers is used alone, the character is output as if it is a character of a string, escaped if necessary, and surrounded by quotes.</p><p>  <code>(format "~~C" #\A)</code> ⟹ <code>A</code><br>  <code>(format "~~+C" #\A)</code> ⟹ <code>"A"</code><br>  <code>(format "~~+C" #\newline)</code> ⟹ <code>"\n"</code><br>  <code>(format "~~@C" "A")</code> ⟹ <code>#\A</code><br>  <code>(format "~~@C" "\t")</code> ⟹ <code>#\tab</code><br>  <code>(format "~~@:C" "©")</code> ⟹ <code>U+00A9</code><br>  <code>(format "~~@:+C" "©")</code> ⟹ <code>COPYRIGHT SIGN</code><br>  <code>(format "~~:C" "©")</code> ⟹ <code>\&#xA9;</code><br>  <code>(format "\~:+C" "©")</code> ⟹ <code>\&copy;</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~d</strong><br><strong>\~D</strong></p> | <p>DECIMAL:  <strong>\~</strong><em><strong>mincol,padchar,groupchar,groupcol</strong></em><strong>D</strong></p><p>The next argument <em>arg</em> is output in decimal radix. <em>arg</em> should be an integer, in which case no decimal point is printed. For floating-point numbers which do not represent an integer, a decimal point and a fractional part are output.</p><p><em>mincol</em> (default: 0) specifies the minimal "width" of the output of the directive in characters with <em>padchar</em> (default: ' ') defining the character that is used to pad the output on the left to make sure it is at least <em>mincol</em> characters long.</p><p>  <code>(format "Number: \~D" 8273)</code> ⟹ <code>Number: 8273</code><br>  <code>(format "Number: \~6D" 8273)</code> ⟹ <code>Number:   8273</code><br>  <code>(format "Number: \~6,'0D" 8273)</code> ⟹ <code>Number: 008273</code></p><p>By default, the number is output without grouping separators. <em>groupchar</em> specifies which character should be used to separate sequences of <em>groupcol</em> digits in the output. Grouping of digits gets enabled with the <code>:</code> modifier.</p><p>  <code>(format "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | \~10:D                                                                                                            | " 1734865)</code> ⟹ <code> | 1,734,865  | </code><br>  <code>(format " | \~10,,'.:D               | " 1734865)</code> ⟹ <code> | 1.734.865  | </code></p><p>A sign is output only if the number is negative. With the modifier <code>@</code> it is possible to force output also of positive signs. To facilitate the localization of output, procedure <code>format</code> supports a locale parameter, which is also available via format config objects. Locale-specific output can be enabled for the <code>~~D</code> directive by using the <code>+</code> modifier.</p><p>  <code>(format 'de\_CH "~~+D" 14321)</code> ⟹ <code>14'321</code></p> |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~b</strong><br><strong>\~B</strong></p> | <p>BINARY:  <strong>\~</strong><em><strong>mincol,padchar,groupchar,groupcol</strong></em><strong>B</strong></p><p>Binary directive <code>\~B</code> is just like decimal directive <code>\~D</code> but it outputs the next argument in binary radix (radix 2) instead of decimal. It uses the space character as the default for <em>groupchar</em> and has a default grouping size of 4 as the default for <em>groupcol</em>.</p><p>  <code>(format "bin(\~D) = ~~B" 178 178)</code> ⟹ <code>bin(178) = 10110010</code><br>  <code>(format "~~:B" 59701)</code> ⟹ <code>1110 1001 0011 0101</code><br>  <code>(format "\~19,'0,'.:B" 31912)</code> ⟹ <code>0111.1100.1010.1000</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~o</strong><br><strong>\~O</strong></p> | <p>OCTAL:  <strong>\~</strong><em><strong>mincol,padchar,groupchar,groupcol</strong></em><strong>O</strong></p><p>Octal directive <code>\~O</code> is just like decimal directive <code>\~D</code> but it outputs the next argument in octal radix (radix 8) instead of decimal. It uses the space character as the default for <em>groupchar</em> and has a default grouping size of 4 as the default for <em>groupcol</em>.</p><p>  <code>(format "bin(\~D) = ~~O" 178 178)</code> ⟹ <code>bin(178) = 262</code><br>  <code>(format "~~:O" 59701)</code> ⟹ <code>16 4465</code><br>  <code>(format "\~9,'0,',:O" 31912)</code> ⟹ <code>0007,6250</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~x</strong><br><strong>\~X</strong></p> | <p>HEXADECIMAL:  <strong>\~</strong><em><strong>mincol,padchar,groupchar,groupcol</strong></em><strong>X</strong></p><p>Hexadecimal directive <code>\~X</code> is just like decimal directive <code>\~D</code> but it outputs the next argument in hexadecimal radix (radix 16) instead of decimal. It uses the colon character as the default for <em>groupchar</em> and has a default grouping size of 2 as the default for <em>groupcol</em>. With modifier <code>+</code>, upper case characters are used for representing hexadecimal digits.</p><p>  <code>(format "bin(~~D) = ~~X" 9968 9968)</code> ⟹ <code>bin(9968) = 26f0</code><br>  <code>(format "~~:X" 999701)</code> ⟹ <code>f:41:15</code><br>  <code>(format "~~+X" 999854)</code> ⟹ <code>F41AE</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~r</strong><br><strong>\~R</strong></p> | <p>RADIX:  <strong>\~</strong><em><strong>radix,mincol,padchar,groupchar,groupcol</strong></em><strong>R</strong></p><p>The next argument <em>arg</em> is expected to be a fixnum number. It will be output with radix <em>radix</em> (default: 10). <em>mincol</em> (default: 0) specifies the minimal "width" of the output of the directive in characters with <em>padchar</em> (default: ' ') defining the character that is used to pad the output on the left to make it at least <em>mincol</em> characters long.</p><p>  <code>(format "Number: \~10R" 1272)</code> ⟹ <code>Number: 1272</code><br>  <code>(format "Number: \~16,8,'0R" 7121972)</code> ⟹ <code>Number: 006cac34</code><br>  <code>(format "Number: ~~2R" 173)</code> ⟹ <code>Number: 10101101</code></p><p>By default, the number is output without grouping separators. <em>groupchar</em> specifies which character should be used to separate sequences of <em>groupcol</em> digits in the output. Grouping of digits is enabled with the <code>:</code> modifier.</p><p>  <code>(format "~~16,8,,':,2:R" 7121972)</code> ⟹ <code>6c:ac:34</code><br>  <code>(format "~~2,14,'0,'.,4:R" 773)</code> ⟹ <code>0011.0000.0101</code></p><p>A sign is output only if the number is negative. With the modifier <code>@</code> it is possible to force output also of positive signs.</p><p>If parameter <em>radix</em> is not specified at all, then an entirely different interpretation is given. <code>~~R</code> outputs <em>arg</em> as a cardinal number in natural language. The form <code>~~:R</code> outputs <em>arg</em> as an ordinal number in natural language. <code>~~@R</code> outputs <em>arg</em> as a Roman numeral.</p><p>  <code>(format "~~R" 572)</code> ⟹ <code>five hundred seventy-two</code><br>  <code>(format "~~:R" 3)</code> ⟹ <code>3rd</code><br>  <code>(format "~~@R" 1272)</code> ⟹ <code>MCCLXXII</code></p><p>Whenever output is provided in natural language, English is used as the language by default. By specifying the <code>+</code> modifier, it is possible to switch the language to the language of the locale provided to procedure <code>format</code>. In fact, modifier <code>+</code> plays two different roles: If the given radix is greater than 10, upper case characters are used for representing alphabetic digits. If the radix is omitted, usage of modifier <code>+</code> enables locale-specific output determined by the <code>locale:</code> parameter of procedure <code>format</code>.</p><p>  <code>(format 'de\_DE "~~+R" 572)</code> ⟹ <code>fünf­hundert­zwei­und­siebzig</code><br>  <code>(format 'de\_CH "\~10+R" 14321)</code> ⟹ <code>14'321</code><br>  <code>(format "\~16R vs \~16+R" 900939 900939)</code> ⟹ <code>dbf4b vs DBF4B</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~f</strong><br><strong>\~F</strong></p> | <p>FIXED FLOAT:  <strong>~~</strong><em><strong>w,d,k,overchar,padchar,groupchar,groupcol</strong></em><strong>F</strong></p><p>The next argument <em>arg</em> is output as a floating-point number in a fixed format (ideally without exponent) of exactly <em>w</em> characters, if <em>w</em> is specified. First, leading <em>padchar</em> characters (default: ' ') are output, if necessary, to pad the field on the left. If <em>arg</em> is negative, then a minus sign is printed. If <em>arg</em> is not negative, then a plus sign is printed if and only if the <code>@</code> modifier was specified. Then a sequence of digits, containing a single embedded decimal point, is printed. If parameter <em>d</em> is provided, then exactly <em>d</em> decimal places are output. This represents the magnitude of the value of <em>arg</em> times 10<em>k</em>, rounded to <em>d</em> fractional digits. There are no leading zeros, except that a single zero digit is output before the decimal point if the printed value is less than 1.0, and this single zero digit is not output after all if <em>w = d</em> + 1.</p><p>If it is impossible to print the value in the required format in a field of width <em>w</em>, then one of two actions is taken: If the parameter <em>overchar</em> is specified, then <em>w</em> copies of this character are printed. If <em>overchar</em> is omitted, then the scaled value of <em>arg</em> is printed using more than <em>w</em> characters.</p><p>If the width parameter <em>w</em> is omitted, then the output is of variable width and a value is chosen for <em>w</em> in such a way that no leading padding characters are needed and exactly <em>d</em> characters will follow the decimal point. For example, the directive <code>~~,2F</code> will output exactly two digits after the decimal point and as many as necessary before the decimal point.</p><p>If <em>d</em> is omitted, then there is no constraint on the number of digits to appear after the decimal point. A value is chosen for <em>d</em> in such a way that as many digits as possible may be printed subject to the width constraint imposed by <em>w</em> and the constraint that no trailing zero digits may appear in the fraction, except that if the fraction is zero, then a single zero digit should appear after the decimal point if permitted by the width constraint.</p><p>If <em>w</em> is omitted, then if the magnitude of <em>arg</em> is so large (or, if <em>d</em> is also omitted, so small) that more than 100 digits would have to be printed, then <em>arg</em> is output using exponential notation instead.</p><p>The <code>\~F</code> directive also supports grouping of the integer part of <em>arg</em>; this can be enabled via the <code>:</code> modifier. <em>groupchar</em> (default: ',') specifies which character should be used to separate sequences of <em>groupcol</em> (default: 3) digits in the integer part of the output. If locale-specific settings should be used, the <code>+</code> modifier needs to be set.</p><p>  <code>(format "\~F" 123.1415926)</code> ⟹ <code>123.1415926</code><br>  <code>(format "~~8F" 123.1415926)</code> ⟹ <code>123.1416</code><br>  <code>(format "~~8,,,'-F" 123.1415926)</code> ⟹ <code>123.1416</code><br>  <code>(format "~~8,,,'-F" 123456789.12)</code> ⟹ <code>--------</code><br>  <code>(format "~~8,,,,'0F" 123.14)</code> ⟹ <code>00123.14</code><br>  <code>(format "~~8,3,,,'0F" 123.1415926)</code> ⟹ <code>0123.142</code><br>  <code>(format "~~,4F" 123.1415926)</code> ⟹ <code>123.1416</code><br>  <code>(format "~~,2\@F" 123.1415926)</code> ⟹ <code>+123.14</code><br>  <code>(format "~~,2,-2\@F" 314.15926)</code> ⟹ <code>+3.14</code><br>  <code>(format "~~,2:F" 1234567.891)</code> ⟹ <code>1,234,567.89</code><br>  <code>(format "~~,2,,,,'',3:F" 1234567.891)</code> ⟹ <code>1'234'567.89</code></p> |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~e</strong><br><strong>\~E</strong></p> | <p>EXPONENTIAL FLOAT:  <strong>~~</strong><em><strong>w,d,e,k,overchar,padchar,expchar</strong></em><strong>E</strong></p><p>The next argument <em>arg</em> is output as a floating-point number in an exponential format of exactly <em>w</em> characters, if <em>w</em> is specified. Parameter <em>d</em> is the number of digits to print after the decimal point, <em>e</em> is the number of digits to use when printing the exponent, and <em>k</em> is a scale factor that defaults to 1.</p><p>First, leading <em>padchar</em> (default: ' ') characters are output, if necessary, to pad the output on the left. If <em>arg</em> is negative, then a minus sign is printed. If <em>arg</em> is not negative, then a plus sign is printed if and only if the <code>@</code> modifier was specified. Then a sequence of digits, containing a single embedded decimal point, is output. The form of this sequence of digits depends on the scale factor <em>k</em>. If <em>k</em> is zero, then <em>d</em> digits are printed after the decimal point, and a single zero digit appears before the decimal point. If <em>k</em> is positive, then it must be strictly less than <em>d</em> + 2 and <em>k</em> significant digits are printed before the decimal point, and <em>d − k</em> + 1 digits are printed after the decimal point. If <em>k</em> is negative, then it must be strictly greater than <em>−d</em>. A single zero digit appears before the decimal point and after the decimal point, first <em>−k</em> zeros are output followed by <em>d + k</em> significant digits.</p><p>Following the digit sequence, the exponent is output following character <em>expchar</em> (default: 'E') and the sign of the exponent, i.e. either the plus or the minus sign. The exponent consists of <em>e</em> digits representing the power of 10 by which the fraction must be multiplied to properly represent the rounded value of <em>arg</em>.</p><p>If it is impossible to print the value in the required format in a field of width <em>w</em>, then one of two actions is taken: If the parameter <em>overchar</em> is specified, then <em>w</em> copies of this character are printed instead of <em>arg</em>. If <em>overchar</em> is omitted, then <em>arg</em> is printed using more than <em>w</em> characters, as many more as may be needed. If <em>d</em> is too small for the specified <em>k</em> or <em>e</em> is too small, then a larger value is used for <em>d</em> or <em>e</em> as may be needed.</p><p>If the <em>w</em> parameter is omitted, then the output is of variable width and a value is chosen for <em>w</em> in such a way that no leading padding characters are needed.</p><p>  <code>(format "~~E" 31.415926)</code> ⟹ <code>3.1415926E+1</code><br>  <code>(format "~~,5E" 0.0003141592)</code> ⟹ <code>3.14159E-4</code><br>  <code>(format "~~,4,2E" 0.0003141592)</code> ⟹ <code>3.1416E-04</code><br>  <code>(format "\~9E" 31.415926)</code> ⟹ <code>3.1416E+1</code><br>  <code>(format "\~10,3,,,,'#E" 31.415926)</code> ⟹ <code>##3.142E+1</code><br>  <code>(format "\~10,4,,3,,'#E" 31.415926)</code> ⟹ <code>#314.16E-1</code><br>  <code>(format "\~7,3,2,,'-E" 31.415926)</code> ⟹ <code>-------</code><br>  <code>(format "\~10,4,,4,,'#@E" 31.415926)</code> ⟹ <code>+3141.6E-2</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~g</strong><br><strong>\~G</strong></p> | <p>GENERAL FLOAT:  <strong>\~</strong><em><strong>w,d,e,k,overchar,padchar,expchar</strong></em><strong>G</strong></p><p>The next argument <em>arg</em> is output as a floating-point number in either fixed-format or exponential notation as appropriate. The format in which to print <em>arg</em> depends on the magnitude (absolute value) of <em>arg</em>. Let <em>n</em> be an integer such that 10n−1 ≤ <em>arg</em> < 10n. If <em>arg</em> is zero, let <em>n</em> be 0. Let <em>ee</em> equal <em>e</em> + 2, or 4 if <em>e</em> is omitted. Let <em>ww</em> equal <em>w</em> − <em>ee</em>, or nil if <em>w</em> is omitted. If <em>d</em> is omitted, first let <em>q</em> be the number of digits needed to print <em>arg</em> with no loss of information and without leading or trailing zeros; then let <em>d</em> equal <em>max(q, min(n, 7))</em>. Let <em>dd</em> equal <em>d − n</em>.</p><p>If 0 ≤ <em>dd</em> ≤ <em>d</em>, then <em>arg</em> is output as if by the format directives:<br>    <code>~~ww,dd,,overchar,padcharF~~ee\@T</code><br>Note that the scale factor <em>k</em> is not passed to the <code>\~F</code> directive. For all other values of <em>dd</em>, <em>arg</em> is printed as if by the format directive:<br>    <code>\~w,d,e,k,overchar,padchar,expcharE</code><br>In either case, an <code>@</code> modifier is specified to the <code>\~F</code> or <code>\~E</code> directive if and only if one was specified to the <code>\~G</code> directive.</p><p>  <code>(format "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | \~G                                                                                                               | " 712.72)</code> ⟹ <code>  | 712.72     | </code><br>  <code>(format " | \~12G                    | " 712.72)</code> ⟹ <code>  | 712.72     | </code><br>  <code>(format "                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | \~9,2G                    | \~9,3,2,3G         | \~9,3,2,0G | " 0.031415 0.031415 0.031415)</code><br>    ⟹ <code> | 3.14E-2              | 314.2E-04          | 0.314E-01  | </code><br>  <code>(format " | \~9,2G                | \~9,3,2,3G         | \~9,3,2,0G | " 0.314159 0.314159 0.314159)</code><br>    ⟹ <code> | 0.31                  | 0.314              | 0.314      | </code><br>  <code>(format " | \~9,2G                 | \~9,3,2,3G         | \~9,3,2,0G | " 3.14159 3.14159 3.14159)</code><br>    ⟹ <code>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | 3.1 | 3.14 | 3.14 | </code><br>  <code>(format " | \~9,2G | \~9,3,2,3G | \~9,3,2,0G | " 314.159 314.159 314.159)</code><br>    ⟹ <code> | 3.14E+2 | 314 | 314 | </code><br>  <code>(format " | \~9,2G | \~9,3,2,3G | \~9,3,2,0G | " 3141.59 3141.59 3141.59)</code><br>    ⟹ <code> | 3.14E+3 | 314.2E+01 | 0.314E+04 | </code></p> |
| **\~$**                                             | <p>DOLLARS FLOAT:  <strong>~~</strong><em><strong>d,n,w,padchar,curchar,groupchar,groupcol</strong></em><strong>$</strong></p><p>The next argument <em>arg</em> is output as a floating-point number in a fixed-format notation that is particularly well suited for outputting monetary values. Parameter <em>d</em> (default: 2) defines the number of digits to print after the decimal point. Parameter <em>n</em> (default: 1) defines the minimum number of digits to print before the decimal point. Parameter <em>w</em> (default: 0) is the minimum total width of the output.</p><p>First, padding and the sign are output. If <em>arg</em> is negative, then a minus sign is printed. If <em>arg</em> is not negative, then a plus sign is printed if and only if the <code>@</code> modifier was specified. If the <code>:</code> modifier is used, the sign appears before any padding, and otherwise after the padding. If the number of characters, including the sign and a potential currency symbol is below width <em>w</em>, then character <em>padchar</em> (default: ' ') is used for padding the number in front of the integer part such that the overall output has <em>w</em> characters. After the padding, the currency symbol <em>curchar</em> is inserted, if available, followed by <em>n</em> digits representing the integer part of <em>arg</em>, prefixed by the right amount of '0' characters. If either parameter <em>groupchar</em> or <em>groupcol</em> is provided, the integer part is output in groups of <em>groupcol</em> characters (default: 3) separated by <em>groupchar</em> (default: ','). After the integer part, a decimal point is output followed by <em>d</em> digits of fraction, properly rounded.</p><p>If the magnitude of <em>arg</em> is so large that the integer part of <em>arg</em> cannot be output with at most <em>n</em> characters, then more characters are generated, as needed, and the total width might overrun as well.</p><p>For cases where a simple currency symbol is not sufficient, it is possible to use a numeric currency code as defined by ISO 4217 for parameter <em>curchar</em>. For positive codes, the shortest currency symbol is being used. For negative currency codes, the corresponding alphabetic code (ignoring the sign) is being used. Library <code>(lispkit system)</code> provides a conventient API to access currency codes.</p><p>By specifying the <code>+</code> modifier, it is possible to enable locale-specific output of the monetary value using the locale provided to <code>format</code>. In this case, also the currency associated with this locale is being used.</p><p>  <code>(format "~~$" 4930.351)</code> ⟹ <code>4930.35</code><br>  <code>(format "~~3$" 4930.351)</code> ⟹ <code>4930.351</code><br>  <code>(format "~~,6$" 4930.351)</code> ⟹ <code>004930.35</code><br>  <code>(format "~~,6,12,'\_$" 4930.351)</code> ⟹ <code>\_\_\_004930.35</code><br>  <code>(format "~~,6,12,'*@$" 4930.351)</code> ⟹ <code>\_\_+004930.35</code><br>  <code>(format "~~,6,12,'\_@:$" 4930.351)</code> ⟹ <code>+\_\_004930.35</code><br>  <code>(format "~~,6,12,'*,'€$" 4930.351)</code> ⟹ <code>\_\_€004930.35</code><br>  <code>(format "~~,6,12,'*,'€@$" 4930.351)</code> ⟹ <code>*+€004930.35</code><br>  <code>(format "~~,,,,,,3$" 4930.351)</code> ⟹ <code>4,930.35</code><br>  <code>(format "~~,6,,,,,3$" 4930.351)</code> ⟹ <code>004,930.35</code><br>  <code>(format "~~,,,,208$" 1234.567)</code> ⟹ <code>kr 1234.57</code><br>  <code>(format "~~,,,,-208$" 1234.567)</code> ⟹ <code>DKK 1234.57</code><br>  <code>(format 'de\_CH "~~+$" 4930.351)</code> ⟹ <code>CHF 4930.35</code><br>  <code>(format 'en\_US "~~,,,,,,3+$" 4930.351)</code> ⟹ <code>$4,930.35</code><br>  <code>(format 'de\_DE "~~,6,14,'\_,,,3+$" 4930.351)</code> ⟹ <code>\_\_004.930,35 €</code></p>                                                |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~%**                                             | <p>NEWLINE:  <strong>~~</strong><em><strong>n</strong></em><strong>%</strong></p><p>This directive outputs <em>n</em> (default: 1) newline characters, thereby terminating the current output line and beginning a new one. No arguments are being consumed. Simply putting <em>n</em> newline escape characters  into the control string would also work, but <code>~~%</code> is often used because it makes the control string look nicer and more consistent.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~&**                                             | <p>FRESHLINE:  <strong>\~</strong><em><strong>n</strong></em><strong>&</strong></p><p>Unless it can be determined that the output is already at the beginning of a line, this directive outputs a newline if <em>n</em> > 0. This conditional newline is followed by <em>n</em> − 1 newlines, it <em>n</em> > 1. Nothing is output if <em>n</em> = 0.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~\|**                                            | <p>PAGE SEPARATOR:  <strong>\~</strong><em><strong>n</strong></em><strong>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | </strong></p><p>This directive outputs <em>n</em> (default: 1) page separator characters <code>#\page</code>.</p> |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~\~**                                            | <p>TILDE:  <strong>~~</strong><em><strong>n</strong></em><strong>~~</strong></p><p>This directive outputs <em>n</em> (default: 1) tilde characters.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~p</strong><br><strong>\~P</strong></p> | <p>PLURAL:  <strong>\~P</strong></p><p>Depending on the next argument <em>arg</em>, which is expected to be an integer value, a different string is output. If <em>arg</em> is not equal to 1, a lowercase <code>s</code> is output. If <em>arg</em> is equal to 1, nothing is output.</p><p>If the <code>:</code> modifier is provided, the last argument is used instead for <em>arg</em>. This is useful after outputting a number using <code>\~D</code>. With the <code>@</code> modifier, <code>y</code> is output if <em>arg</em> is 1, or <code>ies</code> if it is not.</p><p>  <code>(format "~~D tr~~:@P/~~D win~~:P" 7 1)</code> ⟹ <code>7 tries/1 win</code><br>  <code>(format "~~D tr~~:@P/~~D win~~:P" 1 0)</code> ⟹ <code>1 try/0 wins</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| <p><strong>\~t</strong><br><strong>\~T</strong></p> | <p>TABULATE:  <strong>\~</strong><em><strong>colnum,colinc</strong></em><strong>T</strong></p><p>This directive will output sufficient spaces to move the cursor to column <em>colnum</em> (default: 1). If the cursor is already at or beyond column <em>colnum</em>, the directive will output spaces to move the cursor to column <em>colnum + k × colinc</em> for the smallest positive integer <em>k</em> possible, unless <em>colinc</em> (default: 1) is zero, in which case no spaces are output if the cursor is already at or beyond column <em>colnum</em>.</p><p>If modifier <code>@</code> is provided, relative tabulation is performed. In this case, the directive outputs <code>colnum</code> spaces and then outputs the smallest non-negative number of additional spaces necessary to move the cursor to a column that is a multiple of <em>colinc</em>. For example, the directive <code>\~3,8\@T</code> outputs three spaces and then moves the cursor to a "standard multiple-of-eight tab stop" if not at one already. If the current output column cannot be determined, however, then <em>colinc</em> is ignored, and exactly <em>colnum</em> spaces are output.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~\***                                            | <p>IGNORE ARGUMENT:  <strong>~~</strong><em><strong>n</strong></em><strong>\*</strong></p><p>The next <em>n</em> (default: 1) arguments are ignored. If the <code>:</code> modifier is provided, arguments are "ignored backwards", i.e. <code>~~:*</code> backs up in the list of arguments so that the argument last processed will be processed again. <code>~~n:\*</code> backs up <em>n</em> arguments. When within a <code>~~{</code> construct, the ignoring (in either direction) is relative to the list of arguments being processed by the iteration.</p><p>The form <code>~~n@\*</code> is an "absolute goto" rather than a "relative goto": the directive goes to the <em>n</em>-th argument, where 0 means the first one. <em>n</em> defaults to 0 for this form, so <code>~~@*</code> goes back to the first argument. Directives after a <code>~~n@\*</code> will take arguments in sequence beginning with the one gone to. When within a <code>~~{</code> construct, the "goto" is relative to the list of arguments being processed by the iteration.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~?**                                             | <p>INDIRECTION:  <strong>~~?</strong></p><p>The next argument <em>arg</em> must be a string, and the one after it <em>lst</em> must be a sequence (e.g. an array). Both arguments are consumed by the directive. <em>arg</em> is processed as a format control string, with the elements of the list <em>lst</em> as the arguments. Once the recursive processing of the control string has been finished, then processing of the control string containing the <code>~~?</code> directive is resumed.</p><p>  <code>(format "\~? \~D" "\[\~A ~~D]" '("Foo" 5) 7)</code> ⟹ <code>\[Foo 5] 7</code><br>  <code>(format "~~? \~D" "\[\~A ~~D]" '("Foo" 5 14) 7)</code> ⟹ <code>\[Foo 5] 7</code></p><p>Note that in the second example, three arguments are supplied to the control string <code>"(~~A ~~D)"</code>, but only two are processed and the third is therefore ignored.</p><p>With the <code>@</code> modifier, only one argument is directly consumed. The argument must be a string. It is processed as part of the control string as if it had appeared in place of the <code>~~@?</code> directive, and any directives in the recursively processed control string may consume arguments of the control string containing the <code>~~@?</code> directive.</p><p>  <code>(format "~~@? \~D" "\[\~A ~~D]" "Foo" 5 7)</code> ⟹ <code>\[Foo 5] 7</code><br>  <code>(format "~~@? \~D" "\[\~A \~D]" "Foo" 5 14 7)</code> ⟹ <code>\[Foo 5] 14</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~(…\~)**                                         | <p>CONVERSION:  <strong>~~(</strong><em><strong>str</strong></em><strong>~~)</strong></p><p>The contained control string <em>str</em> is processed, and what it produces is subject to a conversion. Without the <code>+</code> modifier, a <em>case conversion</em> is performed. <code>~~(</code> converts every uppercase character to the corresponding lowercase character, <code>~~:(</code> capitalizes all words, <code>~~@(</code> capitalizes just the first word and forces the rest to lowercase, and <code>~~:@(</code> converts every lowercase character to the corresponding uppercase character. In the following example, <code>~~@(</code> is used to cause the first word produced by <code>~~R</code> to be capitalized:</p><p>  <code>(format "~~@(~~R~~) error~~:P" 0)</code> ⟹ <code>Zero errors</code><br>  <code>(format "~~@(~~R~~) error~~:P" 1)</code> ⟹ <code>One error</code><br>  <code>(format "~~@(~~R~~) error~~:P" 23)</code> ⟹ <code>Twenty-three errors</code></p><p>If the <code>+</code> modifier is provided together with the <code>:</code> modifier, all characters corresponding to named XML entities are being converted into names XML entities. If modifier <code>@</code> is added, then only those characters are converted which conflict with XML syntax. The modifier combination <code>+@</code> converts the output by stripping off all diacritics. Modifier <code>+</code> only will escape characters such that the result can be used as a Scheme string literal.</p><p>  <code>(format "~~+:(~~A~~)" "© 2021–2023 TÜV")</code><br>    ⟹ <code>\&copy; 2021\&ndash;2023 T\&Uuml;V</code><br>  <code>(format "~~+:@(~~A~~)" "\<a href="t.html">© TÜV\</a>")</code><br>    ⟹ <code>\&lt;a href=\&quot;t.html\&quot;\&gt;© TÜV\&lt;/a\&gt;</code><br>  <code>(format "~~+@(~~A~~)" "épistèmê")</code><br>    ⟹ <code>episteme</code><br>  <code>(format "~~+(~~A~~)" "Hello "World"\n")</code><br>    ⟹ <code>Hello "World"</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~\[…\~]**                                        | <p>CONDITIONAL:  <strong>~~\[</strong><em><strong>str0</strong></em><strong>~~;</strong><em><strong>str1</strong></em><strong>~~;…~~;</strong><em><strong>strn</strong></em><strong>~~]</strong></p><p>This is a set of control strings, called clauses, one of which is chosen and used. The clauses are separated by <code>~~;</code> and the construct is terminated by <code>~~]</code>.</p><p><em>Without default:</em>  From a conditional directive ~~\[<em>str0</em>~~;<em>str1</em>~~;…~~;<em>strn</em>~~], the <em>arg</em>-th clause is selected, where the first clause is number 0. If a prefix parameter is given as <code>~~n\[</code>, then the parameter <em>n</em> is used instead of an argument. This is useful only if the parameter is specified by <code>#</code>, to dispatch on the number of arguments remaining to be processed. If <em>arg</em> or <em>n</em> is out of range, then no clause is selected and no error is signaled. After the selected alternative has been processed, the control string continues after the <code>~~]</code>.</p><p><em>With default:</em>  Whenever the directive has the form ~~\[<em>str0</em>~~;<em>str1</em>~~;…~~:;<em>default</em>~~], i.e. the last clause is separated via <code>~~:;</code>, then the conditional directive has a default clause which gets performed whenever no other clause could be selected.</p><p><em>Optional selector:</em>  Whenever the directive has the form ~~:\[<em>none</em>~~;<em>some</em>~~] the <em>none</em> control string is chosen if <em>arg</em> is <code>nil</code>, otherwise the <em>some</em> control string is chosen.</p><p><em>Boolean selector:</em>  Whenever the directive has the form ~~+\[<em>false</em>~~;<em>true</em>~~] the <em>false</em> control string is chosen if <em>arg</em> is the boolean value <code>false</code>, otherwise the <em>some</em> control string is chosen.</p><p><em>Selector test:</em>  Whenever the directive has the form ~~@\[<em>true</em>~~], the next argument <em>arg</em> is tested for being non-<code>nil</code>. If <em>arg</em> is not <code>nil</code>, then the argument is not used up by the <code>\~@\[</code> directive but remains as the next one to be processed, and the one clause <em>true</em> is processed. If <em>arg</em> is <code>nil</code>, then the argument is used up, and the clause is not processed. The clause therefore should normally use exactly one argument, and may expect it to be non-<code>nil</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~{…\~}**                                         | <p>ITERATION:  <strong>~~</strong><em><strong>n</strong></em><strong>{</strong><em><strong>str</strong></em><strong>~~}</strong></p><p>The iteration directive is used to control how a sequence is output. Thus, the next argument <em>arg</em> should be a sequence which is used as a list of arguments as if for a recursive call to <code>format</code>. The string <em>str</em> is used repeatedly as the control string until all elements from <em>arg</em> are consumed. Each iteration can absorb as many elements of <em>arg</em> as it needs. For instance, if <em>str</em> uses up two arguments by itself, then two elements of <em>arg</em> will get used up each time around the loop. If before any iteration step the sequence is empty, then the iteration is terminated. Also, if a prefix parameter <em>n</em> is given, then there will be at most <em>n</em> repetitions of processing of <em>str</em>. Finally, the <code>~~^</code> directive can be used to terminate the iteration prematurely. If the iteration is terminated before all the remaining arguments are consumed, then any arguments not processed by the iteration remain to be processed by any directives following the iteration construct.</p><p>  <code>(format "Winners:~~{ ~~A~~}." '("Fred" "Harry" "Jill"))</code><br>    ⟹ <code>Winners: Fred Harry Jill.</code><br>  <code>(format "Winners: ~~{~~#\[~~;~~A~~:;~~A, ~~]~~}." '("Fred" "Harry" "Jill"))</code><br>    ⟹ <code>Winners: Fred, Harry, Jill.</code><br>  <code>(format "Pairs:~~{ <~~A,~~S>~~}." '("A" 1 "B" 2 "C" 3))</code><br>    ⟹ <code>Pairs: \<A, 1> \<B, 2> \<C, 3>.</code></p><p><code>~~:</code><em><code>n,m</code></em><code>{</code><em><code>str</code></em><code>~~}</code> is similar, but the argument should be a list of sublists. At each repetition step (capped by <em>n</em>), one sublist is used as the list of arguments for processing <em>str</em> with an iteration cap of <em>m</em>. On the next repetition, a new sublist is used, whether or not all elements of the last sublist had been processed.</p><p>  <code>(format "Pairs:~~:{ <~~A,~~S>~~}." '(("A" 1) ("B" 2) ("C" 3)))</code><br>    ⟹ <code>Pairs: \<A, 1> \<B, 2> \<C, 3>.</code></p><p><code>~~@{</code><em><code>str</code></em><code>~~}</code> is similar to <code>~~{</code><em><code>str</code></em><code>~~}</code>, but instead of using one argument that is a sequence, all the remaining arguments are used as the list of arguments for the iteration.</p><p>  <code>(format "Pairs:~~@{ <~~A,~~S>~~}." "A" 1 "B" 2 "C" 3)</code><br>    ⟹ <code>Pairs: \<A, 1> \<B, 2> \<C, 3>.</code></p><p><code>~~:@{</code><em><code>str</code></em><code>~~}</code> combines the features of <code>~~:{</code><em><code>str</code></em><code>~~}</code> and <code>~~@{</code><em><code>str</code></em><code>~~}</code>. All the remaining arguments are used, and each one must be a sequence. On each iteration, the next argument is used as a list of arguments to <em>str</em>.</p><p>  <code>(format "Pairs:~~:@{ <~~A,~~S>~~}." '("A" 1) '("B" 2) '("C" 3))</code><br>    ⟹ <code>Pairs: \<A, 1> \<B, 2> \<C, 3>.</code></p><p>Terminating the repetition directive with <code>~~:}</code> instead of <code>~~}</code> forces <em>str</em> to be processed at least once, even if the initial sequence is empty. However, it will not override an explicit prefix parameter of zero. If <em>str</em> is empty, then an argument is used as <em>str</em>. It must be a string and precede any arguments processed by the iteration.</p>                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~<…\~>**                                         | <p>JUSTIFICATION:   <strong>~~</strong><em><strong>mincol,colinc,minpad,padchar,maxcol,elchar</strong></em><strong><</strong><em><strong>str</strong></em><strong>~~></strong></p><p>This directive justifies the text produced by processing control string <em>str</em> within a field which is at least <em>mincol</em> columns wide (default: 0). <em>str</em> may be divided up into segments via directive <code>\~;</code>, in which case the spacing is evenly divided between the text segments.</p><p>With no modifiers, the leftmost text segment is left-justified in the field and the rightmost text segment is right-justified. If there is only one text element, it is right-justified. The <code>:</code> modifier causes spacing to be introduced before the first text segment. The <code>@</code> modifier causes spacing to be added after the last text segment. The <em>minpad</em> parameter (default: 0) is the minimum number of padding characters to be output between each segment. Whenever padding is needed, the padding character <em>padchar</em> (default: ' ') is used. If the total width needed to satisfy the constraints is greater than <em>mincol</em>, then the width used is <em>mincol + k × colinc</em> for the smallest possible non-negative integer <em>k</em> with <em>colinc</em> defaulting to 1.</p><p>  <code>(format "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | ~~10,,,'.\<foo~~;bar\~>                                                                                           | ")</code> ⟹ <code>         | foo....bar | </code><br>  <code>(format " | ~~10,,,'.:\<foo~~;bar\~> | ")</code> ⟹ <code>         | ..foo..bar | </code><br>  <code>(format "                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | ~~10,,,'.:@\<foo~~;bar\~> | ")</code> ⟹ <code> | ..foo.bar. | </code><br>  <code>(format "                         | ~~10,,,'.\<foobar~~> | ")</code> ⟹ <code> | ....foobar | </code><br>  <code>(format " | ~~10,,,'.:\<foobar~~> | ")</code> ⟹ <code> | ....foobar | </code><br>  <code>(format "                         | ~~10,,,'.@\<foobar~~> | ")</code> ⟹ <code> | foobar.... | </code><br>  <code>(format " | ~~10,,,'.:@\<foobar~~> | ")</code> ⟹ <code> | ..foobar.. | </code></p><p>Note that <em>str</em> may include format directives. All the clauses in <em>str</em> are processed in order. It is the resulting pieces of text that are justified. The <code>~~^</code> directive may be used to terminate processing of the clauses prematurely, in which case only the completely processed clauses are justified.</p><p>If the first clause of a <code>~~<</code> directive is terminated with <code>~~:;</code> instead of <code>~~;</code>, then it is used in a special way. All of the clauses are processed, but the first one is not used in performing the spacing and padding. When the padded result has been determined, then, if it fits on the current line of output, it is output, and the text for the first clause is discarded. If, however, the padded text does not fit on the current line, then the text segment for the first clause is output before the padded text. The first clause ought to contain a newline (such as a <code>~~%</code> directive). The first clause is always processed, and so any arguments it refers to will be used. The decision is whether to use the resulting segment of text, not whether to process the first clause. If the <code>~~:;</code> has a prefix parameter <em>n</em>, then the padded text must fit on the current line with <em>n</em> character positions to spare to avoid outputting the first clause’s text.</p><p>For example, the control string in the following example can be used to print a list of items separated by comma without breaking items over line boundaries, beginning each line with <code>;;</code>. The prefix parameter 1 in <code>~~1:;</code> accounts for the width of the comma that will follow the justified item if it is not the last element in the list, or the period if it is. If <code>~~:;</code> has a second prefix parameter, like below, then it is used as the width of the line, overriding the line width as specified by <code>format</code>'s <code>linewidth:</code> parameter (default: 80).</p><p>  <code>(format "~~%;; ~~{~~<~~%;; ~~1,30:; ~~S~~>~~^,~~}.~~%"</code><br>  <code>'("first line" "second" "a long third line"</code><br>  <code>"fourth" "fifth"))</code><br>    ⟹ <br>         <code>;; "first line", "second",</code><br>         <code>;; "a long third line",</code><br>         <code>;; "fourth", "fifth".</code><br>         </p><p>If there is only one text segment <em>str</em> and parameter <em>maxcol</em> is provided and the length of the output of <em>str</em> is exceeding <em>maxcol</em>, then the output is truncated at width <em>maxcol - 1</em> and the ellipsis character <em>elchar</em> (default: '…') is inserted at the end.</p> |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~^**                                             | <p>UP AND OUT:  <strong>~~^</strong></p><p><em>Continue:</em>  The <code>~~^</code> directive is an escape construct. If there are no more arguments remaining to be processed, then the immediately enclosing <code>~~{</code> or <code>~~<</code> directive is terminated. If there is no such enclosing directive, then the entire formatting operation is terminated. In the case of <code>~~<</code>, the formatting is performed, but no more segments are processed before doing the justification. The <code>~~^</code> directive should appear only at the beginning of a <code>~~<</code> clause, because it aborts the entire clause it appears in, as well as all following clauses. <code>~~^</code> may appear anywhere in a <code>~~{</code> construct.</p><p>  <code>(format "Done.~~^ ~~D warning~~:P.~~^ ~~D error~~:P.")</code><br>    ⟹ <code>Done.</code><br>  <code>(format "Done.~~^ ~~D warning~~:P.~~^ ~~D error~~:P." 3)</code><br>    ⟹ <code>Done. 3 warnings.</code><br>  <code>(format "Done.~~^ ~~D warning~~:P.~~^ ~~D error~~:P." 1 5)</code><br>    ⟹ <code>Done. 1 warning. 5 errors.</code></p><p>If the directive has the form <code>~~</code><em><code>n</code></em><code>^</code>, then termination occurs if <em>n</em> is zero. If the directive has the form <code>~~</code><em><code>n,m</code></em><code>^</code>, termination occurs if the value of <em>n</em> equals the value of <em>m</em>. If the directive has the form <code>~~</code><em><code>n,m,o</code></em><code>^</code>, termination occurs if <em>n</em> ≤ <em>m</em> ≤ <em>o</em>. Of course, this is useless if all the prefix parameters are literals. At least one of them should be a <code>#</code> or a <code>v</code> parameter.</p><p><em>Break:</em>  If <code>~~^</code> is used within a <code>~~:{</code> directive, then it merely terminates the current iteration step because in the standard case, it tests for remaining arguments of the current step only and the next iteration step commences immediately. To terminate the entire iteration process, use <code>~~:^</code>. <code>~~:^</code> may only be used if the directive it would terminate is <code>~~:{</code> or <code>~~:@{</code>. The entire iteration process is terminated if and only if the sublist that is supplying the arguments for the current iteration step is the last sublist (in the case of terminating a <code>~~:{</code> directive) or the last argument to that call to format (in the case of terminating a <code>~~:@{</code> directive).</p><p>Note that while <code>~~^</code> is equivalent to <code>~~#^</code> in all circumstances, <code>~~:^</code> is not equivalent to <code>~~#:^</code> because the latter terminates the entire iteration if and only if no arguments remain for the current iteration step, as opposed to no arguments remaining for the entire iteration process.</p><p>  <code>(format "~~:{/~~A~~^ …~~}",</code><br>  <code>'(("hot" "dog") ("hamburger") ("ice" "cream") ("french" "fries")))</code><br>    ⟹ <code>/hot …/hamburger/ice …/french …</code><br>  <code>(format "~~:{/~~A~~:^ …~~}"</code><br>  <code>'(("hot" "dog") ("hamburger") ("ice" "cream") ("french" "fries")))</code><br>    ⟹ <code>/hot …/hamburger …/ice …/french</code><br>  <code>(format "~~:{/~~A~~#:^ …~~}"</code><br>  <code>'(("hot" "dog") ("hamburger") ("ice" "cream") ("french" "fries")))</code><br>    ⟹ <code>/hot …/hamburger</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |
| **\~\`…\~‘**                                        | <p>UPACK:  <strong>\~`</strong><em><strong>str</strong></em><strong>~‘</strong></p><p>This directive is used to format composite objects, such as rational numbers, complex numbers, colors, date-time objects, error objects, records, etc. Such objects get decomposed into a sequence of individual values which are formatted by the <em>str</em> control string.</p><p>The next argument <em>arg</em> can be any Scheme object. If there is a decomposition predefined for this type of objects, it is applied to <em>arg</em> and <em>str</em> is used to format the resulting sequence of values. If no decomposition is possible, <em>str</em> is output assuming there is one argument <em>arg</em>.</p><p>  <code>(format "~S~:* = ~`(~~S, ~~S)~~‘" 17/3)</code> ⟹ <code>17/3 = (17, 3)</code><br>  <code>(format "Bits =~~`~*~{ ~D~}~‘" (bitset 1 2 7))</code> ⟹ <code>Bits = 1 2 7</code><br>  <code>(format "Color: ~`R=\~F, G=\~F, B=~~F~~‘" (color 0.3 1.0 0.74))</code><br>    ⟹ <code>Color: R=0.3, G=1.0, B=0.74</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |                                                                                                                   |                            |            |                              |                          |                            |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                           |                    |            |                                                      |                      |                    |            |                              |                       |                    |            |                                                      |                       |                    |            |                              |                        |                    |            |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |     |      |      |                              |        |            |            |                                                   |         |     |     |                              |        |            |            |                                                   |         |           |           |             |

## Formatting configurations

A few formatting directives provided by procedure `format` require access to environment variables such as the locale, the width of tab characters, the length of lines, etc. Also the type-specific customization of the formatting of native and user-defined objects, e.g. via the `~S` directive, is based on a formatting control registry defined by an environment variable.

All relevant environment variables are bundled together into *format config* objects. Format configurations are organized hierarchically. Each format configuration optionally refers to a parent configuration. It inherits all environment variables and allows their values to be overridden.

The root of this format configuration hierarchy constitutes `base-format-config`. Typically, changes to this object impact all invocations of `format`, unless format is called with a custom format config object which is not derived from `base-format-config`. Without a custom format config, `format` reads the environment variables from the *current format config* parameter `current-format-config` (which, by default, inherits from `base-format-config`). Like every other parameter object, it is possible to define a new config dynamically via `parameterize`.

Format config objects are also used in combination with type-specific formatting as provided by the `~S` directive, as explained in the next section.

## Type-specific formatting

Procedure `format` provides great means to format numbers, characters, strings, as well as sequences, i.e. lists and vectors. But as soon as values of data types encapsulating their state have to be output, only the default textual representation is supported, which is also used when a value is output via procedure `write`.

For this reason, procedure `format` supports the customization of how composite objects are formatted. The approach for doing this is simple: Internally, a composite object can be mapped ("unpacked") into a vector of "field values". These field values are then interpreted as arguments for an object type-specific control string which defines how the field values of such objects are formatted. If there is no object type-specific control string available, the object is output as if it was written via procedure `write`.

The following example shows how to customize the formatting of objects defined by a record type. The following record is used to model colored 2-dimensional points:

```scheme
(define-record-type <point>
  (make-point x y c)
  point?
  (x point-x)
  (y point-y)
  (c point-color))
```

By default, objects of type `<point>` are output in the following way:

```scheme
(define pt (make-point 7 13 (color 0.5 0.9 0)))
(format "~S" pt)
 ⇒ "#<record <point>: x=7, y=13, c=#<color 0.5 0.9 0.0>>"
```

LispKit defines a type tag for every type. This type tag will later be used to define a custom format for records of type `<point>`. We can retrieve the type tag for type `<point>` via procedure `record-type-tag`:

```scheme
(define point-type-tag (record-type-tag <point>))
```

Now we can define a custom format for objects of type `<point>` in which we refer to the unpacked fields in the order as defined in the `<point>` record type definition following a fixnum value denoting the identity of the record. The following control string formats `<point>` records in this way: `point{x=?,y=?,color=?}`. Note that it skips the record identity via the `~*` directive.

```scheme
"point{x=~*~S,y=~S,c=~S}"
```

`format` refers to a number of environment variables via a formatting configuration (see previous section). The default configuration is defined by definition `base-format-config` and it includes custom type-specific formats. With procedure `format-config-control-set!` we can declare that all objects of type `<point>` should be formatted with the control string shown above:

```scheme
(format-config-control-set!
  base-format-config
  point-type-tag
  "point{x=~*~S,y=~S,c=~S}")
```

Formatting records of type `<point>` via the `~S` directive is now based on this new control string.

```scheme
(format "~S" pt)
 ⇒ "point{x=7,y=13,c=#<color 0.5 0.9 0.0>}"
```

If we wanted to also change how colors are formatted, we could do that in a similar way:

```scheme
(format-config-control-set!
  base-format-config
  color-type-tag
  "color{~S, ~S, ~S}")
```

Now colors are formatted differently:

```scheme
(format "~S" pt)  ⇒ "point{x=7,y=13,c=#<color 0.5 0.9 0.0>}"
(format "~S" (color 1.0 0.3 0.7))  ⇒ "color{1.0, 0.3, 0.7}"
```

If we wanted to change the way how colors are formatted only in the context of formatting points, we could do that by creating a formatting configuration for colors and associate it only with the formatting control string for points. The following code first removes the global color format so that colors are formatted again using the default mechanism. Then it redefines the formatting control for points by also specifying a format configuration that is used while applying the point formatting control string.

```scheme
(format-config-control-remove! base-format-config color-type-tag)
(format-config-control-set!
  base-format-config
  point-type-tag 
  "point{x=~*~S,y=~S,c=~S}"
  (format-config (list color-type-tag "color{~S, ~S, ~S}")))
(format "~S" (color 1.0 0.3 0.7))  ⇒ "#<color 1.0 0.3 0.7>"
(format "~S" pt)  ⇒ "point{x=7,y=13,c=color{0.5, 0.9, 0.0}}"
```

## API

**format-config-type-tag**     <img src="/files/viHiVHsCY8Wn2TeCgWJj" alt="" data-size="line">

Symbol representing the `format-config` type. The `type-for` procedure of library `(lispkit type)` returns this symbol for all formatting configurations objects.

**base-format-config**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Formatting configurations can have parent configurations from which all formatting environment variables are being inherited. `base-format-config` is the root formatting configuration for `repl-format-config` and `current-format-config`.

**repl-format-config**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

The formatting configuration that a read-eval-print loop might use for displaying the result of an evaluation. Initially, `repl-format-config` is set to an empty formatting configuration with parent `base-format-config`.

**current-format-config**     <img src="/files/mK8eMQUj1oS8rq8TeU89" alt="" data-size="line">

Parameter object referring to the current formatting configuration that is used as a default whenever no specific formatting configuration is specified, e.g. by procedure `format`. Initially, `current-format-config` is set to an empty formatting configuration with parent `base-format-config`.

**(format&#x20;*****\[port] \[config] \[locale] \[tabw \[linew]] cntrl arg ...*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

`format` is the universal formatting procedure provided by library `(lispkit format)`. `format` creates formatted output by outputting the characters of the control string *cntrl* while interpreting formatting directives embedded in *cntrl*. Each formatting directive is prefixed with a tilde which might be preceded by formatting parameters and modifiers. The next character identifies the formatting directive and thus determines what output is being generated by the directive. Most directives use one or more arguments *arg* as input.

Formatting configuration *config* defines environment variables influencing the output of some formatting directives. If *config* is not provided, the formatting configuration from parameter object `current-format-config` is used. For convenience, some environment variables, such as *locale*, can be overridden if they are provided when `format` is being invoked. *locale* refers to a locale identifier like `en_US` that is used by locale-specific formatting directives. *tabw* defines the maximum number of space characters that correspond to a single tab character. *linew* specifies the number of characters per line; this is used by the justification directive only.

**(format-config?&#x20;*****obj*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if *obj* is a formatting configuration; otherwise `#f` is returned.

**(format-config&#x20;*****\[parent] \[locale] \[tabw \[linew]] (tag cntrl \[config]) ...*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Creates a new formatting configuration with *parent* as parent configuration. If *parent* is not provided explicitly, `current-format-config` is used. If *parent* is `#f`, the new formatting configuation will not have a parent configuration. *locale* refers to a locale identifier like `en_US` that is used by locale-specific formatting directives. *tabw* defines the maximum number of space characters that correspond to a single tab character. *linew* specifies the maximum number of characters per line.

**(make-format-config&#x20;*****parent*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(make-format-config&#x20;*****parent locale*****)**\
\&#xNAN;**(make-format-config&#x20;*****parent locale tabw*****)**\
\&#xNAN;**(make-format-config&#x20;*****parent locale tabw linew*****)**

Creates a new formatting configuration with *parent* as parent configuration. If *parent* is `#f`, the new formatting configuation does not have a parent configuration. The remaining arguments define overrides for the environment variables inherited from *parent*.

*locale* refers to a locale identifier like `en_US` that is used by locale-specific formatting directives. *tabw* defines the maximum number of space characters that correspond to a single tab character. *linew* specifies the maximum number of characters per line.

**(copy-format-config&#x20;*****config*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(copy-format-config&#x20;*****config collapse?*****)**

Returns a copy of formatting configuration *config*. If either *collapse?* is omitted or set to `#f`, a 1:1 copy of *config* is being made. If *collapse?* is set to true, a new format config without parent configuration is created which contains the same values for the supported formatting environment variables as *config*.

**(merge-format-config&#x20;*****child parent*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Merges the format configurations *child* and *parent* by creating a new collapsed copy of *child* whose parent configuration *parent* is.

**(format-config-locale)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-locale&#x20;*****config*****)**

Returns the locale defined by format configuration *config*. If *config* defines a locale itself, it is being returned. Otherwise, the locale of the parent configuration of *config* gets returned. If *config* is not provided, the default configuration `current-format-config` is used.

**(format-config-locale-set!&#x20;*****locale*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-locale-set!&#x20;*****config locale*****)**

Sets the locale of the format configuration *config* to *locale*. If *locale* is `#f`, the locale setting gets removed from *config* (but might still get inherited from *config*'s parents). If *config* is not provided, the default configuration `current-format-config` gets mutated.

**(format-config-tabwidth)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-tabwidth&#x20;*****config*****)**

Returns the width of a tab character in terms of space characters defined by format configuration *config*. If *config* defines a tab width itself, it is being returned. Otherwise, the tab width of the parent configuration of *config* gets returned. If *config* is not provided, the default configuration `current-format-config` is used.

**(format-config-tabwidth-set!&#x20;*****tabw*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-tabwidth-set!&#x20;*****config tabw*****)**

Sets the tab width of the format configuration *config* to *tabw*. If *tabw* is `#f`, the tab width setting gets removed from *config* (but might still get inherited from *config*'s parents). If *config* is not provided, the default configuration `current-format-config` gets mutated. The "tab width" is the maximum number of space characters representing one tab character.

**(format-config-linewidth)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-linewidth&#x20;*****config*****)**

Returns the maximum number of characters per line defined by format configuration *config*. If *config* defines a line width itself, it is being returned. Otherwise, the line width of the parent configuration of *config* gets returned. If *config* is not provided, the default configuration `current-format-config` is used.

**(format-config-linewidth-set!&#x20;*****linew*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-linewidth-set!&#x20;*****config linew*****)**

Sets the line width of the format configuration *config* to *linew*. If *linew* is `#f`, the line width setting gets removed from *config* (but might still get inherited from *config*'s parents). If *config* is not provided, the default configuration `current-format-config` gets mutated. The "line width" is the maximum number of characters per line.

**(format-config-control-set!&#x20;*****tag cntrl*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-control-set!&#x20;*****tag cntrl sconf*****)**\
\&#xNAN;**(format-config-control-set!&#x20;*****config tag cntrl*****)**\
\&#xNAN;**(format-config-control-set!&#x20;*****config tag cntrl sconf*****)**

Declares for formatting configuration *config* that objects whose type has type tag *tag* are being formatted with control string *cntrl* by formatting directive `~S`. If formatting configuration *sconf* is provided, it is used as a type-specific configuration that is merged with the current configuration when `~S` formats objects of type tag *tag*. If *cntrl* is `#f`, type-specific formatting rules for *tag* are being removed from *conf* (but might still be inherited from the parent of *conf*). If *cntrl* is `#t`, native formatting is being forced for *tag*, no matter what is inherited from the parent of *config*. If *config* is not provided, the default configuration `current-format-config` gets mutated.

**(format-config-control-remove!&#x20;*****tag*****)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-control-remove!&#x20;*****config tag*****)**

Removes any type-specific formatting with directive `~S` for objects whose type has tag *tag* from formatting configuration *config*. If *config* is not provided, the default configuration `current-format-config` gets mutated.

**(format-config-controls)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-controls&#x20;*****config*****)**

Returns a list of type tags, i.e. symbols, for which there is a type-specific formatting control string defined by formatting configuration *config* or its parents. If *config* is not provided, the default configuration `current-format-config` gets mutated.

**(format-config-parent)**     <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(format-config-parent&#x20;*****config*****)**

Returns the parent configuration of format configuration *config*. If *config* is not provided, the default configuration `current-format-config` is used. `format-config-parent` returns `#f` if *config* does not have a parent formatting configuration.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.lisppad.app/libraries/lispkit/lispkit-format.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
