Characters are objects that represent printed characters such as letters and digits. Characters are written using the notation #\<character> or #\<character name>. For example:
- ; lower case letter
- ; upper case letter
- ; left parenthesis
- ; the space character
- ; the preferred way to write a space
- ; the newline character
Case is significant in #\<character>, but not in #\<character name>.
If <character> in #\<character> is alphabetic, then the character following <character> must be a delimiter character such as a space or parenthesis. This rule resolves the ambiguous case where, for example, the sequence of characters “#\ space” could be taken to be either a representation of the space character or a representation of the character “#\ s” followed by a representation of the symbol “pace.”
Characters written in the #\ notation are self-evaluating. That is, they do not have to be quoted in programs.
Some of the procedures that operate on characters ignore the difference between upper case and lower case. The procedures that ignore case have “-ci” (for “case insensitive”) embedded in their names.
These procedures impose a total ordering on the set of characters. It is guaranteed that under this ordering:
- The upper case characters are in order. For example, (char<? #\A #\B) returns #t.
- The lower case characters are in order. For example, (char<? #\a #\b) returns #t.
- The digits are in order. For example, (char<? #\0 #\9) returns #t.
- Either all the digits precede all the upper case letters, or vice versa.
- Either all the digits precede all the lower case letters, or vice versa.
Some implementations may generalize these procedures to take more than two arguments, as with the corresponding numerical predicates.
These procedures are similar to char=? et cetera, but they treat upper case and lower case letters as the same. For example, (char-ci=? #\A #\a) returns #t. Some implementations may generalize these procedures to take more than two arguments, as with the corresponding numerical predicates.
These procedures return #t if their arguments are alphabetic, numeric, whitespace, upper case, or lower case characters, respectively, otherwise they return #f. The following remarks, which are specific to the ASCII character set, are intended only as a guide: The alphabetic characters are the 52 upper and lower case letters. The numeric characters are the ten decimal digits. The whitespace characters are space, tab, line feed, form feed, and carriage return.
Given a character, char->integer returns an exact integer representation of the character. Given an exact integer that is the image of a character under char->integer, integer->char returns that character. These procedures implement order-preserving isomorphisms between the set of characters under the
char<=?ordering and some subset of the integers under the <= ordering. That is, if(char<=? a b) => #t and (<= x y) => #t
and x and y are in the domain of integer->char, then(<= (char->integer a) (char->integer b)) ==> #t (char<=? (integer->char x) (integer->char y)) ==> #t