Next: , Previous: FORMAT Control-Flow Operations, Up: Formatted Output


22.3.8 FORMAT Miscellaneous Operations

22.3.8.1 Tilde Left-Paren: Case Conversion

~(str~)

The contained control string str is processed, and what it produces is subject to case conversion.

With no flags, every uppercase character is converted to the corresponding lowercase character.

~:( capitalizes all words, as if by string-capitalize.

~@( capitalizes just the first word and forces the rest to lower case.

~:@( converts every lowercase character to the corresponding uppercase character.

In this example ~@( is used to cause the first word produced by ~@R to be capitalized:

 (format nil "~@R ~(~@R~)" 14 14)
 "XIV xiv"
 (defun f (n) (format nil "~@(~R~) error~:P detected." n))  F
 (f 0)  "Zero errors detected."
 (f 1)  "One error detected."
 (f 23)  "Twenty-three errors detected."

When case conversions appear nested, the outer conversion dominates, as illustrated in the following example:

 (format nil "~@(how is ~:(BOB SMITH~)?~)")
  "How is bob smith?"
 not "How is Bob Smith?"
22.3.8.2 Tilde Right-Paren: End of Case Conversion

~) terminates a ~(. The consequences of using it elsewhere are undefined.

22.3.8.3 Tilde P: Plural

If arg is not eql to the integer 1, a lowercase s is printed; if arg is eql to 1, nothing is printed. If arg is a floating-point 1.0, the s is printed.

~:P does the same thing, after doing a ~:* to back up one argument; that is, it prints a lowercase s if the previous argument was not 1.

~@P prints y if the argument is 1, or ies if it is not. ~:@P does the same thing, but backs up first.

 (format nil "~D tr~:@P/~D win~:P" 7 1)  "7 tries/1 win"
 (format nil "~D tr~:@P/~D win~:P" 1 0)  "1 try/0 wins"
 (format nil "~D tr~:@P/~D win~:P" 1 3)  "1 try/3 wins"