x-lang

← Index

x/type/char

Character operations as the Char class.

ASCII only. Classification, case conversion, and comparison homed on the Char class.

Class Char

(Char ->int c)

The integer code point of a character.

Parameters:

Returns: INTEGER — Code point (0-255 for ASCII/byte chars)

Examples:

(Char ->int #\A) => 65

(Char from-int n)

The character for an integer code point.

Parameters:

Returns: CHARACTER — The character

Examples:

(Char from-int 97) => #\a

(Char alphabetic? c)

Test whether a character is alphabetic.

Parameters:

Returns: BOOL — True if c is a letter A-Z or a-z

Examples:

(Char alphabetic? #\q) => #t
(Char alphabetic? #\7) => #f

(Char numeric? c)

Test whether a character is a digit.

Parameters:

Returns: BOOL — True if c is a digit 0-9

Examples:

(Char numeric? #\7) => #t

(Char whitespace? c)

Test whether a character is whitespace (space, tab, newline, CR, FF).

Parameters:

Returns: BOOL — True if c is whitespace

Examples:

(Char whitespace? #\space) => #t
(Char whitespace? #\a) => #f

(Char upper-case? c)

Test whether a character is uppercase.

Parameters:

Returns: BOOL — True if c is uppercase A-Z

Examples:

(Char upper-case? #\A) => #t

(Char lower-case? c)

Test whether a character is lowercase.

Parameters:

Returns: BOOL — True if c is lowercase a-z

Examples:

(Char lower-case? #\A) => #f

(Char upcase c)

Convert a character to uppercase.

Parameters:

Returns: CHARACTER — Uppercase version of c, or c unchanged

Examples:

(Char upcase #\a) => #\A
(Char upcase #\1) => #\1

(Char downcase c)

Convert a character to lowercase.

Parameters:

Returns: CHARACTER — Lowercase version of c, or c unchanged

Examples:

(Char downcase #\A) => #\a

(Char =? a b)

Test whether two characters are equal.

Parameters:

Returns: BOOL — True if characters are equal

Examples:

(Char =? #\a #\a) => #t

(Char <? a b)

Test whether a character is less than another by code point.

Parameters:

Returns: BOOL — True if a comes before b

Examples:

(Char <? #\a #\b) => #t

(Char >? a b)

Test whether a character is greater than another by code point.

Parameters:

Returns: BOOL — True if a comes after b

Examples:

(Char >? #\a #\b) => #f

(Char <=? a b)

Test whether a character is less than or equal to another.

Parameters:

Returns: BOOL — True if a is equal to or comes before b

Examples:

(Char <=? #\a #\a) => #t

(Char >=? a b)

Test whether a character is greater than or equal to another.

Parameters:

Returns: BOOL — True if a is equal to or comes after b

Examples:

(Char >=? #\a #\b) => #f

(Char ci=? a b)

Case-insensitive character equality.

Parameters:

Returns: BOOL — True if characters are equal ignoring case

Examples:

(Char ci=? #\a #\A) => #t

(Char ci<? a b)

Case-insensitive character less-than.

Parameters:

Returns: BOOL — True if a < b ignoring case

Examples:

(Char ci<? #\a #\B) => #t

(Char ci>? a b)

Case-insensitive character greater-than.

Parameters:

Returns: BOOL — True if a > b ignoring case

Examples:

(Char ci>? #\b #\A) => #t

(Char ci<=? a b)

Case-insensitive character less-than-or-equal.

Parameters:

Returns: BOOL — True if a <= b ignoring case

Examples:

(Char ci<=? #\A #\a) => #t

(Char ci>=? a b)

Case-insensitive character greater-than-or-equal.

Parameters:

Returns: BOOL — True if a >= b ignoring case

Examples:

(Char ci>=? #\a #\B) => #f