Characters¶
Overview¶
Characters are objects that represent printed characters such as letters and digits.
Character Procedures¶
- (char-alphabetic? char)
Returns
#trueif char is an alphabetic character, and#falseotherwise.- Parameters:
char (char) – The character to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (char-alphabetic? #\a) #true --> (char-alphabetic? #\Z) #true --> (char-alphabetic? #\7) #false
- (char-numeric? char)
Returns
#trueif char is a numeric digit (0-9), and#falseotherwise.- Parameters:
char (char) – The character to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (char-numeric? #\5) #true --> (char-numeric? #\x) #false
- (char-whitespace? char)
Returns
#trueif char is a whitespace character (like space, tab, or newline), and#falseotherwise.- Parameters:
char (char) – The character to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (char-whitespace? #\space) #true --> (char-whitespace? #\newline) #true --> (char-whitespace? #\a) #false
- (char-upper-case? char)
Returns
#trueif char is an uppercase letter, and#falseotherwise.- Parameters:
char (char) – The character to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (char-upper-case? #\A) #true --> (char-upper-case? #\a) #false
- (char-lower-case? char)
Returns
#trueif char is a lowercase letter, and#falseotherwise.- Parameters:
char (char) – The character to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (char-lower-case? #\z) #true --> (char-lower-case? #\Z) #false
- (digit-value char)
If char is a numeric digit, this procedure returns its integer value (0-9). If char is not a digit, it returns
#false.- Parameters:
char (char) – The character to convert.
- Returns:
An integer from 0-9 or #false.
- Return type:
integer or boolean
Example:
--> (digit-value #\7) 7 --> (digit-value #\a) #false
Case Conversion Procedures¶
- (char-upcase char)
Returns the uppercase equivalent of char. If char is not a lowercase letter, it is returned unchanged.
- Parameters:
char (char) – The character to convert.
- Returns:
The uppercase version of the character.
- Return type:
char
Example:
--> (char-upcase #\a) #\A --> (char-upcase #\B) #\B
- (char-downcase char)
Returns the lowercase equivalent of char. If char is not an uppercase letter, it is returned unchanged.
- Parameters:
char (char) – The character to convert.
- Returns:
The lowercase version of the character.
- Return type:
char
Example:
--> (char-downcase #\A) #\a --> (char-downcase #\b) #\b
- (char-foldcase char)
Applies Unicode case-folding to char. For most characters, this is the same as
char-downcase, but it handles special cases for robust case-insensitive comparison.- Parameters:
char (char) – The character to convert.
- Returns:
The folded-case version of the character.
- Return type:
char
Example:
--> (char-foldcase #\A) #\a --> (char-foldcase #\ς) ; Greek final sigma #\σ
Case-Insensitive Comparison Procedures¶
- (char-ci=? char1 char2 char3 ...)
Returns
#trueif all characters are the same when ignoring case.Representative Example:
--> (char-ci=? #\a #\A) #true --> (char-ci=? #\z #\Z #\z) #true --> (char-ci=? #\a #\b) #false
- (char-ci<? char1 char2 char3 ...)
- (char-ci<=? char1 char2 char3 ...)
- (char-ci>? char1 char2 char3 ...)
- (char-ci>=? char1 char2 char3 ...)
These procedures compare characters in a case-insensitive manner, returning
#trueif the arguments are in monotonically increasing, non-decreasing, decreasing, or non-increasing order, respectively.
- (string-ci=? string1 string2 string3 ...)
Returns
#trueif all strings are equal when ignoring case.Representative Example:
--> (string-ci=? "scheme" "Scheme" "SCHEME") #true --> (string-ci=? "hello" "goodbye") #false
- (string-ci<? string1 string2 string3 ...)
Returns
#trueif the strings are in lexicographically increasing order, ignoring case.Representative Example:
--> (string-ci<? "alpha" "Beta") #true --> (string-ci<? "a" "B" "c") #true --> (string-ci<? "zeta" "alpha") #false
- (string-ci<=? string1 string2 string3 ...)
- (string-ci>? string1 string2 string3 ...)
- (string-ci>=? string1 string2 string3 ...)
These procedures compare strings lexicographically in a case-insensitive manner, returning
#trueif the arguments are in monotonically non-decreasing, decreasing, or non-increasing order, respectively.