13. CHARACTERS
This chapter contains the following sections:
13.1 Character Attributes
13.2 Predicates on Characters
13.3 Character Construction and Selection
13.4 Character Conversions
13.5 Character Control-bit Functions
Characters are used to represent printed symbols such as letters and digits, as well as control characters such as newline. Character are represented in the same way as fixnums, that is directly .Rather than their virtual address specifying some object in virtual memory, the bit pattern representing the character is embedded into the virtual address. This greatly improves the efficiency of handling individual characters.
Thus if two characters are to be compared for equality, the eq function will suffice in Star Sapphire. Portable code should use the eql function because not all Common LISP implementations use a direct representation for characters.
To see how characters are written, see printed representation of characters.
ASNI Common LISP has revised extensively the treatment of characters as defined in Steele, first edition; however these changes will only impact code which goes beyond the standard character set. For now the Star Sapphire character implementation is strictly based on Steele, first edition. The documentation will note any differences with ANSI Common LISP.
13.1 Character Attributes
Every Common LISP character has three attributes: code, bits and font. These are typically bits which are embedded in the character representation.
The code attribute distinguishes between various characters and correspond to the numeric value of the character.
The bits attribute is used to store shift information, typically with regard to the shift, control and alt (or meta) keys. In this implementation the 256 extended ASCII characters are all assigned bits attributes.
The font attribute is not supported by Star Sapphire, but is maintained for compatibility.
The following three constants can be found defined in init0.lsp:
char-code-limit
char-font-limit
char-bits-limit
These constants indicate the upper exclusive bound on the given attribute in a given implementation. The char-font-limit and char-bits-limit constants have been removed from ANSI Common LISP.
13.2 Predicates on Characters
The following entries define predicates which can be used on characters:
standard-char-p
graphic-char-p
string-char-p
alpha-char-p
upper-case-p
lower-case-p
both-case-p
digit-char-p
alphanumericp
These predicates compare character objects using the implementation-dependent total ordering on characters, in a manner analogous to numeric comparisons by = and related functions.
The total ordering on Star Sapphire characters is determined by their value in the ASCII code.
char=
char/=
char<
char>
char<=
char>=
The following predicates do the same thing but ignore case:
char-equal
char-not-equal
char-lessp
char-greaterp
char-not-greaterp
char-not-lessp
13.3 Character Construction and Selection
These functions may be used to extract attributes of a character and to construct new characters.
char-code
char-bits
char-font
code-char
make-char
ANSI Common LISP has eliminated char-bits, char-font, and make-char and changed the arguments to code-char.
13.4 Character Conversions
These functions perform various transformations on characters, including case conversions.
character
char-upcase
char-downcase
digit-char
char-int
int-char
char-name
name-char
13.5 Character Control-bit Functions
The first version of Common LISP specified four bit names: Control, Meta, Hyper and Super; these had the weights 1,2,4, and 8 respectively. All of these names are supported in Star Sapphire; however, only Control and Meta are implemented (see extended ASCII characters).
The following constants, defined in init0.lsp, are retained for compatibility with the above mentioned values:
char-control-bit
char-meta-bit
char-super-bit
char-hyper-bit
The following functions allow access to the bits attribute:
char-bit
set-char-bit
ANSI Common LISP has eliminated char-control-bit, char-meta-bit, char-super-bit, char-hyper-bit, char-bit and set-char-bit.