Go to the previous, next section.

External Representation of Characters

Characters are written using the notation #\character or #\character-name. For example:

#\a                     ; lowercase letter
#\A                     ; uppercase letter
#\(                     ; left parenthesis
#\space                 ; the space character
#\newline               ; the newline character


Case is significant in #\character, but not in #\character-name. If character in #\character is a letter, character must be followed by a delimiter character such as a space or parenthesis. Characters written in the #\ notation are self-evaluating; you don't need to quote them.

A character name may include one or more bucky bit prefixes to indicate that the character includes one or more of the keyboard shift keys Control, Meta, Super, Hyper, or Top (note that the Control bucky bit prefix is not the same as the ASCII control key). The bucky bit prefixes and their meanings are as follows (case is not significant):

Key             Bucky bit prefix        Bucky bit
---             ----------------        ---------

Meta            M- or Meta-                 1
Control         C- or Control-              2
Super           S- or Super-                4
Hyper           H- or Hyper-                8
Top             T- or Top-                 16

For example,

#\c-a                   ; Control-a
#\meta-b                ; Meta-b
#\c-s-m-h-a             ; Control-Meta-Super-Hyper-A

The following character-names are supported, shown here with their ASCII equivalents:

Character Name          ASCII Name
--------------          ----------

altmode                 ESC
backnext                US
backspace               BS
call                    SUB
linefeed                LF
page                    FF
return                  CR
rubout                  DEL
space
tab                     HT










In addition, #\newline is either #\linefeed or #\return, depending on the operating system that Scheme is running under. All of the standard ASCII names for non-printing characters are supported:

NUL     SOH     STX     ETX     EOT     ENQ     ACK     BEL
BS      HT      LF      VT      FF      CR      SO      SI
DLE     DC1     DC2     DC3     DC4     NAK     SYN     ETB
CAN     EM      SUB     ESC     FS      GS      RS      US
DEL

procedure+: char->name char [slashify?]

Returns a string corresponding to the printed representation of char. This is the character or character-name component of the external representation, combined with the appropriate bucky bit prefixes.

(char->name #\a)                        =>  "a"
(char->name #\space)                    =>  "Space"
(char->name #\c-a)                      =>  "C-a"
(char->name #\control-a)                =>  "C-a"

Slashify?, if specified and true, says to insert the necessary backslash characters in the result so that read will parse it correctly. In other words, the following generates the external representation of char:

(string-append "#\\" (char->name char #t))

If slashify? is not specified, it defaults to #f.

procedure+: name->char string

Converts a string that names a character into the character specified. If string does not name any character, name->char signals an error.

(name->char "a")                        =>  #\a
(name->char "space")                    =>  #\Space
(name->char "c-a")                      =>  #\C-a
(name->char "control-a")                =>  #\C-a

Go to the previous, next section.