Perfect Developer basic tutorial 2 This page last modified 2011-10-29 (JAC)

Class char

Class char represents characters in some character set.Typically, a Perfect implementation will provide Unicode; it may provide other character sets such as ASCII as well. The required character set is selected when invoking the compiler.

Character literals are written in back-quotes, e.g. `a` (not 'a' as in many programming languages).

Special characters can be expressed using escape sequences (introduced by the backslash character), of which the following are most useful:

`\n` Newline
`\a` Alert (bell)
`\t` Horizontal tab
`\`` Back-quote
`\\` Backslash
`\(123)` The character whose code is the integer literal 123

Methods of class char include unary ">" (successor) and unary "<" (predecessor), both yielding char.
For example, (>`0`) = `1` and (<`C`) = `B`.

A character can be converted to its integer equivalent in the underlying character set using the unary "+" operator. A character object can be created from its integer equivalent by construction, e.g. char{123}.

Other interface members include the following:

function isLetter: bool  true if the character is a letter
function isDigit: bool true if the character is a digit
function isPrintable: bool true if the character is not a control character or space
function digit: nat returns the numerical value corresponding to the character, which must be a digit. For example, `0`.digit = 0
function toString: string returns a string of length 1 containing the character

Class char is a final class, so your own classes cannot inherit from it.

Knowledge round-up quiz

Next:  Class int

 

Save My Place Glossary Language Reference Manual
Tutorials Overview Main site   
Copyright © 1997-2012 Escher Technologies Limited. All rights reserved. Information is subject to change without notice.