Download Sections - MIT Computer Science and Artificial Intelligence Laboratory
Transcript
Chapter 5: Characters (make-char (make-char (make-char (make-char 67 97 97 97 97 0) 1) 2) 3) ⇒ ⇒ ⇒ ⇒ #\a #\M-a #\C-a #\C-M-a char-bits char procedure+ Returns the exact integer representation of char’s bucky bits. For example, ⇒ 0 (char-bits #\a) ⇒ 1 (char-bits #\m-a) ⇒ 2 (char-bits #\c-a) ⇒ 3 (char-bits #\c-m-a) char-code char procedure+ Returns the character code of char, an exact integer. For example, ⇒ 97 (char-code #\a) ⇒ 97 (char-code #\c-a) char-code-limit char-bits-limit variable+ variable+ These variables define the (exclusive) upper limits for the character code and bucky bits (respectively). The character code and bucky bits are always exact non-negative integers, and are strictly less than the value of their respective limit variable. char->integer char integer->char k procedure procedure char->integer returns the character code representation for char. integer->char returns the character whose character code representation is k. In MIT Scheme, if (char-ascii? char) is true, then (eqv? (char->ascii char) (char->integer char)) However, this behavior is not required by the Scheme standard, and code that depends on it is not portable to other implementations. These procedures implement order 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 range of char->integer, then (<= (char->integer a) ⇒ #t (char->integer b)) (char<=? (integer->char x) ⇒ #t (integer->char y)) Note: If the argument to char->integer or integer->char is a constant, the compiler will constant-fold the call, replacing it with the corresponding result. This is a very useful way to denote unusual character constants or ascii codes. char-integer-limit variable+ The range of char->integer is defined to be the exact non-negative integers that are less than the value of this variable (exclusive).