8.5.8 Characters
The character object represents a character.
[94] character = #\ any-character | #\ character-name
[95] character-name = letter (letter | digit | - | .)+
Characters are written using the notation #\character or #\character-name. For example:

•  #\a: lower-case letter a

•  #\A: upper-case letter A

•  #\(: left parenthesis

•  #\ : the space character

•  #\space: the preferred way to write a space
If the character in #\any-character is alphabetic, then the character following any-character shall be a delimiter character such as a space or parenthesis.  This rule resolves the ambiguous case where, for example, the sequence of characters #\ space could be taken to be either a representation of the space character or a representation of the character #\ s followed by a representation of the symbol pace.
The character-name shall be the name of a character declared in the character repertoire declaration.
Characters written in the #\ notation are self-evaluating. That is, they do not have to be quoted in expressions.
8.5.8.1 Character Properties
Every character has a set of named properties.  Each property has a default value.
[96] character-property-declaration = (declare-char-property identifier expression)
This declares identifier to be a character property with the default value equal to the value of expression.
[97] added-char-properties-declaration = (add-char-properties keyword-argument-list character+)
[98] keyword-argument-list = (keyword expression)*
The added-char-properties-declaration adds properties to each of the characters. The keyword-argument-list specifies the properties to be added. The keyword specifies the property name, and the expression specifies the property value. Each property either shall be a property that is pre-defined in this International Standard or it shall be explicitly declared using a character-property-declaration.
The following character property is pre-defined:

•  numeric-equiv: is an integer giving the numeric equivalent of the character or #f.  The default value is #f.
Additional properties are pre-defined for the style language.
8.5.8.2 Language-dependent Operations
Certain operations on characters such as case-conversion and collation are dependent on the natural language for which the characters are being used.  The language data type describes how language-dependent operations should be performed.  Expressions may be evaluated with respect to a current language.  It shall be an error to call procedures which use the current language if there is no current language.
Some of the procedures that operate on characters ignore the difference between upper case and lower case.  The procedures that ignore case have -ci (for case-insensitive) embedded in their names.  These procedures always behave as if they converted their arguments to upper case.  These procedures all use the current language. See section 8.5.8.5, Case-insensitive Character Predicates for these procedures.
(language? obj)
Returns #t if obj is of type language, and otherwise returns #f.
(current-language)
At any point in a computation there may be a current language. current-language returns the current language if there is one, and otherwise returns #f.
[99] default-language-declaration = (declare-default-language expression)
A default-language-declaration declares the current language which is used initially in the evaluation of an expression. The expression shall evaluate to a language object.
(with-language language proc)
The with-language procedure calls proc, which shall be a procedure of no arguments, with language as the current language.
Language Definition
[100] language-definition = (define-language variable collation-specification? | toupper-specification? | tolower-specification?)
A language-definition defines variable to be an object of type language.
Collation
[101] collation-specification = (collate multi-collating-element-specification* | collating-symbol-specification* order-specification )
A collation-specification determines the relative order of strings.

NOTE 20

The syntax of the collation-specification is based on ISO 9945-2, which contains examples that may assist the reader.
[102] multi-collating-element-specification = (element multi-collating-element string)
[103] multi-collating-element = identifier
When two strings are compared, each string is divided up into collating elements.  Each collating element is either a single character or a sequence of consecutive characters that is to be treated as a single unit.  A multi-collating-element-specification declares that the sequence of characters in the string is to be treated as a collating element. Within the order-specification, this collating element is identified by the multi-collating-element. Identifiers declared as multi-collating-elements shall be distinct from those used as weight-identifiers.
[104] collating-symbol-specification = (symbol weight-identifier)
[105] weight-identifier = identifier
A collating-symbol-specification declares that weight-identifier is a symbolic identifier for a weight, which may be used within the order-specification.
[106] order-specification = (order sort-rules collation-entry*)
[107] sort-rules = ( level-sort-rules+ )
Each order specification defines a number of different comparison levels.  If two strings compare equal at the first level, they are compared at the second level.  If they also compare equal at the second level, they are compared at the third level.  This process is repeated until there are no more levels or until the strings compare unequal.  The number of levels in the order specification is determined by the number of level-sort-rules.
[108] level-sort-rules = sort-keyword | ((sort-keyword+))
[109] sort-keyword = forward | backward | position
The level-sort-rules determine for each level how the strings are to be compared.  At a given level, each collating-element in the strings to be compared is assigned zero or more weights.  This results in an ordered list of weights for each string.
The backward and forward sort-keywords determine the comparison direction for the level. If the backward sort-keyword is specified, then comparison proceeds from the last weight to the first; otherwise, it proceeds from the first weight to the last.
If the position sort-keyword is specified, then the position of the collating element corresponding to each weight is considered when comparing weights.  When comparing two weights with different positions, the weight with the earlier position (in the comparison direction) shall collate first.
A single level-sort-rules shall not contain both forward and backward.
[110] collation-entry = (( collating-element level-weight*)) | weight-identifier | collating-element
Each collation entry is associated with a weight determined by its position in the order-specification. The first collation entry is associated with the lowest weight, the second with the next lowest weight, and so on.
When a collation-entry is a weight-identifier, then the effect of the collation-entry is to associate the weight-identifier with the weight with which the collation-entry is associated.
A collation-entry that contains a collating-element serves two purposes.  First, it assigns weights for each level to the collating-element.  Second, it makes collating-element stand for the weight associated with the collation-entry when the collating-element is used in a weight.
If a level-weight is not specified for some level, then the single weight associated with the collation-entry shall be assigned.  For example, a collation-entry of #\a is equivalent to a collation-entry of (#\a #\a).
[111] collating-element = character | multi-collating-element | #t
When #t is used as a collating-element, then the specified weights are assigned to all collating elements to which no weight has been explicitly assigned by a collation-entry.
[112] level-weight = weight | weight-list
[113] weight-list = ( weight* )
The level-weight specifies the weights to be assigned for a particular level.
[114] weight = weight-identifier | multi-collating-element | character | string
Specifying a string is equivalent to specifying a list of the characters it contains.
Case Conversion
[115] toupper-specification = (toupper case-conversion-list)
[116] tolower-specification = (tolower case-conversion-list)
[117] case-conversion-list = ((character character))*
In the case-conversion-list, the upper-case or lower-case equivalent of the first character in each pair is the second character in that pair according as the case-conversion-list occurs in a toupper-specification or a tolower-specification.
8.5.8.3 Character Type Predicate
(char? obj)
Returns #t if obj is a character, and otherwise returns #f.
8.5.8.4 Character Comparison Predicates
(char=? char1 char2)
(char<? char1 char2)
(char>? char1 char2)
(char<=? char1 char2)
(char>=? char1 char2)
These procedures impose a total ordering on the set of characters. All the procedures other than char=? use the current language.
8.5.8.5 Case-insensitive Character Predicates
(char-ci=? char1 char2)
(char-ci<? char1 char2)
(char-ci>? char1 char2)
(char-ci<=? char1 char2)
(char-ci>=? char1 char2)
These procedures are similar to char=? etc., but they treat upper-case and lower-case letters as the same. All these procedures use the current language. For example, (char-ci=? #\A #\a) returns #t.
8.5.8.6 Character Case Conversion
(char-upcase char)
(char-downcase char)
The procedures return the upper- or lower-case equivalent of char as defined by the current language. If char has no upper- or lower-case equivalent, char is returned.
8.5.8.7 Character Properties
(char-property symbol char)
(char-property symbol char obj)
Returns the value of the property symbol of char. If symbol is not a character property, an error is signaled. If char does not have a property symbol, then obj is returned, or if obj was not specified, the default value of the property is returned.