No matching definitions.

tur/char

stdlib/char.tur

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

defopaque

Char

(defopaque Char :int)

a character code point, distinct from int.

Since: parsec-guide-plan P1

defn

int->char

(int->char [i :int] :Char)

the character with the given code.

ia character code (65 is A)

The Char whose code is i.

(char=? (int->char 65) #\A)  ; => true

Since: parsec-guide-plan P1

defn

char->int

(char->int [c :Char] :int)

the code of a character.

cthe character

c's character code as an int.

(char->int #\A)  ; => 65

Since: parsec-guide-plan P1

defn

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.

ia character code

The Char whose code is i.

(char->int (char-lit 65))  ; => 65

Since: parsec-guide-plan P1

defn

char=?

(char=? [a :Char b :Char] :bool)

are two characters the same?

aa character
banother character

true when a and b have the same code.

(char=? #\a #\a)  ; => true
(char=? #\a #\A)  ; => false

Since: parsec-guide-plan P1

defn

char<?

(char<? [a :Char b :Char] :bool)

does a sort strictly before b (by code)?

aa character
banother character

true when a's code is less than b's.

(char<? #\a #\b)  ; => true

Since: parsec-guide-plan P1

defn

char-between?

(char-between? [c :Char lo :Char hi :Char] :bool)

is c within the inclusive range [lo, hi]?

cthe character to test
lothe lowest accepted character
hithe highest accepted character

true when lo <= c <= hi by code.

(char-between? #\q #\a #\z)  ; => true

Since: parsec-guide-plan P1

defn

digit?

(digit? [c :Char] :bool)

is c an ASCII decimal digit, 0 through 9?

cthe character to test

true for 0..9.

(digit? #\7)  ; => true
(digit? #\x)  ; => false

Since: parsec-guide-plan P1

defn

upper?

(upper? [c :Char] :bool)

is c an ASCII upper-case letter?

cthe character to test

true for A..Z.

(upper? #\Q)  ; => true

Since: parsec-guide-plan P1

defn

lower?

(lower? [c :Char] :bool)

is c an ASCII lower-case letter?

cthe character to test

true for a..z.

(lower? #\q)  ; => true

Since: parsec-guide-plan P1

defn

alpha?

(alpha? [c :Char] :bool)

is c an ASCII letter?

cthe character to test

true for a..z and A..Z.

(alpha? #\k)  ; => true
(alpha? #\5)  ; => false

Since: parsec-guide-plan P1

defn

alnum?

(alnum? [c :Char] :bool)

is c an ASCII letter or digit?

cthe character to test

true when (alpha? c) or (digit? c).

(alnum? #\5)  ; => true
(alnum? #\-)  ; => false

Since: parsec-guide-plan P1

defn

space?

(space? [c :Char] :bool)

is c ASCII whitespace?

cthe character to test

true for space, tab, newline, carriage return, vertical tab and form feed.

(space? #\tab)  ; => true

Since: parsec-guide-plan P1

defn

punct?

(punct? [c :Char] :bool)

is c printable ASCII punctuation?

cthe 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

defn

char-upcase

(char-upcase [c :Char] :Char)

the upper-case form of an ASCII lower-case letter.

cthe 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

defn

char-downcase

(char-downcase [c :Char] :Char)

the lower-case form of an ASCII upper-case letter.

cthe 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

defn

char->digit

(char->digit [c :Char] :int)

the numeric value of a decimal digit character.

ca 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

definstance

Eq[Char]

(definstance Eq [Char])

characters are equal when their codes are.

definstance

Ord[Char]

(definstance Ord [Char])

characters order by code.