The functions you've seen so far are the beginning of the built-in mathematical functions. Lisp also supports logarithms: LOG
; exponentiation: EXP
and EXPT
; the basic trigonometric functions: SIN
, COS
, and TAN
; their inverses: ASIN
, ACOS
, and ATAN
; hyperbolic functions: SINH
, COSH
, and TANH
; and their inverses: ASINH
, ACOSH
, and ATANH
. It also provides functions to get at the individual bits of an integer and to extract the parts of a ratio or a complex number. For a complete list, see any Common Lisp reference.
Common Lisp characters are a distinct type of object from numbers. That's as it should be—characters are
The read syntax for characters objects is simple: #
followed by the desired character. Thus, #x
is the character x
. Any character can be used after the #
, including otherwise special characters such as '
, (
, and whitespace. However, writing whitespace characters this way isn't very (human) readable; an alternative syntax for certain characters is #
followed by the character's name. Exactly what names are supported depends on the character set and on the Lisp implementation, but all implementations support the names #Space
instead of #
, though the latter is technically legal. Other semistandard names (that implementations must use if the character set has the appropriate characters) are
The 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 analog to the numeric =
is the function CHAR=
. Like =
, CHAR=
can take any number of arguments and returns true only if they're all the same character. The case- insensitive version is CHAR-EQUAL
.
The rest of the character comparators follow this same naming scheme: the case-sensitive comparators are named by prepending the analogous numeric comparator with CHAR
; the case-insensitive versions spell out the comparator name, separated from the CHAR
with a hyphen. Note, however, that <=
and >=
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 relation between the numeric and character comparison functions.
Numeric Analog | Case-Sensitive | Case-Insensitive |
= | CHAR= | CHAR-EQUAL |
/= | CHAR/= | CHAR-NOT-EQUAL |
< | CHAR< | CHAR-LESSP |
> | CHAR> | CHAR-GREATERP |
<= | CHAR<= | CHAR-NOT-GREATERP |
>= | CHAR>= | CHAR-NOT-LESSP |
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.