manpagez: man pages & more
info r5rs
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.4 Characters

Characters are objects that represent printed characters such as letters and digits. Characters are written using the notation #\<character> or #\<character name>. For example:

#\a

; lower case letter

#\A

; upper case letter

#\(

; left parenthesis

#\

; the space character

#\space

; the preferred way to write a space

#\newline

; 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.

procedure: char? obj

Returns #t if obj is a character, otherwise returns #f.

procedure: char=? char1 char2
procedure: char<? char1 char2
procedure: char>? char1 char2
procedure: char<=? char1 char2
procedure: char>=? char1 char2

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.

library procedure: char-ci=? char1 char2
library procedure: char-ci<? char1 char2
library procedure: char-ci>? char1 char2
library procedure: char-ci<=? char1 char2
library procedure: char-ci>=? char1 char2

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.

library procedure: char-alphabetic? char
library procedure: char-numeric? char
library procedure: char-whitespace? char
library procedure: char-upper-case? letter
library procedure: char-lower-case? letter

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.

procedure: char->integer char
procedure: integer->char n

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
library procedure: char-upcase char
library procedure: char-downcase char

These procedures return a character char2 such that ‘(char-ci=? char char2)’. In addition, if char is alphabetic, then the result of ‘char-upcase’ is upper case and the result of ‘char-downcase’ is lower case.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on October 23, 2011 using texi2html 5.0.

© manpagez.com 2000-2018
Individual documents may contain additional copyright information.