Next: , Previous: Numbers, Up: Simple Data Types


5.5.3 Characters

In Scheme, a character literal is written as #\name where name is the name of the character that you want. Printable characters have their usual single character name; for example, #\a is a lower case a.

Most of the “control characters” (those below codepoint 32) in the ASCII character set, as well as the space, may be referred to by longer names: for example, #\tab, #\esc, #\stx, and so on. The following table describes the ASCII names for each character.

0 = #\nul 1 = #\soh 2 = #\stx 3 = #\etx
4 = #\eot 5 = #\enq 6 = #\ack 7 = #\bel
8 = #\bs 9 = #\ht 10 = #\nl 11 = #\vt
12 = #\np 13 = #\cr 14 = #\so 15 = #\si
16 = #\dle 17 = #\dc1 18 = #\dc2 19 = #\dc3
20 = #\dc4 21 = #\nak 22 = #\syn 23 = #\etb
24 = #\can 25 = #\em 26 = #\sub 27 = #\esc
28 = #\fs 29 = #\gs 30 = #\rs 31 = #\us
32 = #\sp

The “delete” character (octal 177) may be referred to with the name #\del.

Several characters have more than one name:

Alias Original
#\space #\sp
#\newline #\nl
#\tab #\ht
#\backspace #\bs
#\return #\cr
#\page #\np
#\null #\nul

— Scheme Procedure: char? x
— C Function: scm_char_p (x)

Return #t iff x is a character, else #f.

— Scheme Procedure: char=? x y

Return #t iff x is the same character as y, else #f.

— Scheme Procedure: char<? x y

Return #t iff x is less than y in the ASCII sequence, else #f.

— Scheme Procedure: char<=? x y

Return #t iff x is less than or equal to y in the ASCII sequence, else #f.

— Scheme Procedure: char>? x y

Return #t iff x is greater than y in the ASCII sequence, else #f.

— Scheme Procedure: char>=? x y

Return #t iff x is greater than or equal to y in the ASCII sequence, else #f.

— Scheme Procedure: char-ci=? x y

Return #t iff x is the same character as y ignoring case, else #f.

— Scheme Procedure: char-ci<? x y

Return #t iff x is less than y in the ASCII sequence ignoring case, else #f.

— Scheme Procedure: char-ci<=? x y

Return #t iff x is less than or equal to y in the ASCII sequence ignoring case, else #f.

— Scheme Procedure: char-ci>? x y

Return #t iff x is greater than y in the ASCII sequence ignoring case, else #f.

— Scheme Procedure: char-ci>=? x y

Return #t iff x is greater than or equal to y in the ASCII sequence ignoring case, else #f.

— Scheme Procedure: char-alphabetic? chr
— C Function: scm_char_alphabetic_p (chr)

Return #t iff chr is alphabetic, else #f.

— Scheme Procedure: char-numeric? chr
— C Function: scm_char_numeric_p (chr)

Return #t iff chr is numeric, else #f.

— Scheme Procedure: char-whitespace? chr
— C Function: scm_char_whitespace_p (chr)

Return #t iff chr is whitespace, else #f.

— Scheme Procedure: char-upper-case? chr
— C Function: scm_char_upper_case_p (chr)

Return #t iff chr is uppercase, else #f.

— Scheme Procedure: char-lower-case? chr
— C Function: scm_char_lower_case_p (chr)

Return #t iff chr is lowercase, else #f.

— Scheme Procedure: char-is-both? chr
— C Function: scm_char_is_both_p (chr)

Return #t iff chr is either uppercase or lowercase, else #f.

— Scheme Procedure: char->integer chr
— C Function: scm_char_to_integer (chr)

Return the number corresponding to ordinal position of chr in the ASCII sequence.

— Scheme Procedure: integer->char n
— C Function: scm_integer_to_char (n)

Return the character at position n in the ASCII sequence.

— Scheme Procedure: char-upcase chr
— C Function: scm_char_upcase (chr)

Return the uppercase character version of chr.

— Scheme Procedure: char-downcase chr
— C Function: scm_char_downcase (chr)

Return the lowercase character version of chr.