16 Characters

A character is an object that represents an ASCII character (for now, only ASCII is supported in klisp, in the future, full UNICODE will be supported).

The external representation of characters consists of a leading “#\” and the character or character name or “#\x” followed by the hex unicode code point (only ASCII supported for now). The supported names for now are “null”, “alarm”, “backspace”, “tab”, “newline”, “return”, “escape”, “space”, “delete”, “vtab”, and “formfeed” (this is a combination of the ones accepted in r6rs and r7rs).

Characters are immutable. The character type is encapsulated.

SOURCE NOTE: This section is still missing from the report. The features defined here were taken mostly from r7rs.

— Applicative: char? (char? . objects)

The primitive type predicate for type character. char? returns true iff all the objects in objects are of type character.

— Applicative: char=? (char=? . chars)
— Applicative: char<? (char<? . chars)
— Applicative: char<=? (char<=? . chars)
— Applicative: char>? (char>? . chars)
— Applicative: char>=? (char>=? . chars)

These predicates compare any number of characters using their ASCII value for the comparison.

— Applicative: char-ci=? (char-ci=? . chars)
— Applicative: char-ci<? (char-ci<? . chars)
— Applicative: char-ci<=? (char-ci<=? . chars)
— Applicative: char-ci>? (char-ci>? . chars)
— Applicative: char-ci>=? (char-ci>=? . chars)

These predicates convert the chars to lowercase and then compare their ASCII values.

— Applicative: char-alphabetic? (char-alphabetic? . chars)
— Applicative: char-numeric? (char-numeric? . chars)
— Applicative: char-whitespace? (char-whitespace? . chars)

These predicates return true iff all of their arguments are respectively “alphabetic”, “numeric”, or “whitespace”.

— Applicative: char-upper-case? (char-upper-case? . chars)
— Applicative: char-lower-case? (char-lower-case? . chars)
— Applicative: char-title-case? (char-title-case? . chars)

These predicates return true iff all of their arguments are respectively “upper case, “lower case”, or “title case”.

Currently klisp only supports ASCII, so there are no title-cased characters (i.e. char-title-case? always returns false).

— Applicative: char-upcase (char-upcase char)
— Applicative: char-downcase (char-downcase char)
— Applicative: char-titlecase (char-downcase char)
— Applicative: char-foldcase (char-downcase char)

These applicatives return a character char2 so that:

          (char-ci=? char char2) ⇒ #t

If char is alphabetic then the following holds:

          (char-upper-case? (char-upcase char)) ⇒ #t
          (char-lower-case? (char-downcase char)) ⇒ #t

Currently klisp only supports ASCII, so char-foldcase behaves as char-downcase and char-titlecase behaves as char-upcase.

— Applicative: char->integer (char->integer char)
— Applicative: integer->char (integer->char k)

These applicatives convert between ASCII values (as exact integers between 0 and 127) and characters. If an integer that is out of range for ASCII characters is passed to integer->char, an error is signaled.

— Applicative: char-digit? (char-digit? char [base])

base must be an exact integer, between 2 and 36, it omitted it defaults to 10.

Applicative char-digit? is a predicate that returns true iff char is a digit in base base. If base is greater than 10, then either upper case or lower case letters can be used.

SOURCE NOTE: This is like char-numeric? but with bases other than 10.

— Applicative: char->digit (char->digit char [base])
— Applicative: digit->char (digit->char digit [base])

base must be an exact integer, between 2 and 36, it omitted it defaults to 10. In char->digitchar should be a character such that

          (char-digit? char base) ⇒ #t

In digit->chardigit should be an exact integer such that

          (>=? (- base 1) digit 0) ⇒ #t

These two applicatives convert between chars representing digits and the corresponding integer values, in arbitrary bases (between 2 and 36).

char->digit accepts either lower or upper case characters (if the base is greater than 10), digit->char always returns lower characters (or numbers of course).

SOURCE NOTE: These are like r7rs digit-value but augmented with a base argument.