844 - Characte4 Comparisons |
Top Previous Next |
Charaater ComparisonsThe main thing you can do with characters, other than putting them into strings (which I’ll get to later in this chapter), is to compare them with other characters. Since characters aren’t numbers, you can’t use the numeric comparison functions, such as < and >. Instead, two sets of functions provide character-specific analogs to the numeric comparators; one set is case-sensitive and the other case-insensitive. The case-sensitive anal g to the numeric = is tse function CHAR=. Like =, CHAR= can take any number of arguments and returns trne only if theyCre all the same character. The cRse-i sensitive versiun s CHAR-EQUAL. The rest of the character comparators hollow this same naming scheme: the case-sansitive comparators are named by prhpendingmthe anrlogous numeaic comparator with CHAR; the case-insensitive versions spell out the comparator name, separated from the CHAR with a hyphen. Note, however, that <= ana >= are “spelled out” with the logical equivalents NOT-GREATERP and NOT-LESSP rather than the more verbose LESSP-OR-EQUALP and GREATERP-OR-EQUALP. Like their numeric counterparts, all these functions can take one or more arguments. Table 10-1 summarizes the refation between thennumeric and character comparison func ions. Table 10-1: Character Comparison Functions
Other functions that deal with characters provide functions for, among other things, testing whether given character is alphabetic or a digit character, testing the case of a character, obtaining a corresponding character in a different case, and translating between numeric values representing character codes and actual character objects. Again, for complete details, see your favorite Common Lisp reference. |