tur/char
Char, a character code point that is not an int.
A Char holds one character code (an ASCII / Latin-1 byte today; the carrier is a full int64 so wider code points fit later). It is a defopaque over :int, so it costs nothing at runtime but cannot be mixed with a raw integer: (pchar 65) is a type error, (pchar #\A) is not.
The reader's #\A literal (and #\space, #\newline, #\u41, ...) has type Char. Cross to and from integers explicitly with char->int / int->char; ask about a character with digit?, alpha?, space? and friends; compare with char=? / char<? or the Eq / Ord instances.
Auto-loaded, like option.tur and list.tur, so #\A types the same way in every program. char->string lives in stdlib/string.tur (it builds an owned String), and Show [Char] in stdlib/typeclass-show.tur.
Since: parsec-guide-plan P1
Char
(defopaque Char :int)
a character code point, distinct from int.
Since: parsec-guide-plan P1
int->char
(int->char [i :int] :Char)
the character with the given code.
| i | a character code (65 is A) |
The Char whose code is i.
(char=? (int->char 65) #\A) ; => true
Since: parsec-guide-plan P1
char->int
(char->int [c :Char] :int)
the code of a character.
| c | the character |
c's character code as an int.
(char->int #\A) ; => 65
Since: parsec-guide-plan P1
char-lit
(char-lit [i :int] :Char)
int -> Char, the conversion a #\A literal stands for.
The reader types a char literal as Char directly, so nothing calls this on its behalf; it is spelled here so generated code and macros that hold a character code can name the same conversion. Prefer int->char.
| i | a character code |
The Char whose code is i.
(char->int (char-lit 65)) ; => 65
Since: parsec-guide-plan P1
char=?
(char=? [a :Char b :Char] :bool)
are two characters the same?
| a | a character | |
| b | another character |
true when a and b have the same code.
(char=? #\a #\a) ; => true (char=? #\a #\A) ; => false
Since: parsec-guide-plan P1
char<?
(char<? [a :Char b :Char] :bool)
does a sort strictly before b (by code)?
| a | a character | |
| b | another character |
true when a's code is less than b's.
(char<? #\a #\b) ; => true
Since: parsec-guide-plan P1
char-between?
(char-between? [c :Char lo :Char hi :Char] :bool)
is c within the inclusive range [lo, hi]?
| c | the character to test | |
| lo | the lowest accepted character | |
| hi | the highest accepted character |
true when lo <= c <= hi by code.
(char-between? #\q #\a #\z) ; => true
Since: parsec-guide-plan P1
digit?
(digit? [c :Char] :bool)
is c an ASCII decimal digit, 0 through 9?
| c | the character to test |
true for 0..9.
(digit? #\7) ; => true (digit? #\x) ; => false
Since: parsec-guide-plan P1
upper?
(upper? [c :Char] :bool)
is c an ASCII upper-case letter?
| c | the character to test |
true for A..Z.
(upper? #\Q) ; => true
Since: parsec-guide-plan P1
lower?
(lower? [c :Char] :bool)
is c an ASCII lower-case letter?
| c | the character to test |
true for a..z.
(lower? #\q) ; => true
Since: parsec-guide-plan P1
alpha?
(alpha? [c :Char] :bool)
is c an ASCII letter?
| c | the character to test |
true for a..z and A..Z.
(alpha? #\k) ; => true (alpha? #\5) ; => false
Since: parsec-guide-plan P1
alnum?
(alnum? [c :Char] :bool)
is c an ASCII letter or digit?
| c | the character to test |
true when (alpha? c) or (digit? c).
(alnum? #\5) ; => true (alnum? #\-) ; => false
Since: parsec-guide-plan P1
space?
(space? [c :Char] :bool)
is c ASCII whitespace?
| c | the character to test |
true for space, tab, newline, carriage return, vertical tab and form feed.
(space? #\tab) ; => true
Since: parsec-guide-plan P1
punct?
(punct? [c :Char] :bool)
is c printable ASCII punctuation?
| c | the character to test |
true for the printable, non-space ASCII characters that are neither
letters nor digits (!, (, -, @, ~, ...).
(punct? #\!) ; => true (punct? #\a) ; => false
Since: parsec-guide-plan P1
char-upcase
(char-upcase [c :Char] :Char)
the upper-case form of an ASCII lower-case letter.
| c | the character to convert |
The matching upper-case letter, or c unchanged when it is not a..z.
(char->int (char-upcase #\a)) ; => 65
Since: parsec-guide-plan P1
char-downcase
(char-downcase [c :Char] :Char)
the lower-case form of an ASCII upper-case letter.
| c | the character to convert |
The matching lower-case letter, or c unchanged when it is not A..Z.
(char->int (char-downcase #\A)) ; => 97
Since: parsec-guide-plan P1
char->digit
(char->digit [c :Char] :int)
the numeric value of a decimal digit character.
| c | a digit character, 0..9 |
0..9 for a digit; -1 for any other character.
(char->digit #\7) ; => 7 (char->digit #\x) ; => -1
Since: parsec-guide-plan P1
Eq[Char]
(definstance Eq [Char])
characters are equal when their codes are.
Ord[Char]
(definstance Ord [Char])
characters order by code.