Next: , Previous: Characters, Up: Characters


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

In addition to the standard character syntax, MIT Scheme also supports a general syntax that denotes any Unicode character by its scalar value. This notation is #\U+scalar-value, where scalar-value is a sequence of hexadecimal digits for a valid scalar value. So the above examples could also be written like this:

     #\U+61                  ; lowercase letter
     #\U+41                  ; uppercase letter
     #\U+28                  ; left parenthesis
     #\U+20                  ; the space character
     #\U+0A                  ; the newline character

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, or Hyper (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

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 the same as #\linefeed (but this may change in the future, so you should not depend on it). 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