retroforth/book/Programming-Techniques-Working-With-Characters
crc 2d491d2502 book: expand coverage of characters
FossilOrigin-Name: d60b665ede2f2c2ffda26a8d51a184955f759044da712442ad471746a681c9a4
2019-03-19 15:12:16 +00:00

65 lines
1.2 KiB
Text

# Working With Characters
RETRO provides words for working with ASCII characters.
## Prefix
Character constants are returned using the `$` prefix.
## Namespace
Words operating on characters are in the `c:` namespace.
## Classification
RETRO provides a number of words to determine if a character
fits into predefined groups.
The primary words for this are:
* `c:consonant?`
* `c:digit?`
* `c:letter?`
* `c:lowercase?`
* `c:uppercase?`
* `c:visible?`
* `c:vowel?`
* `c:whitespace?`
There are also corresponding "not" forms:
* `c:-consonant?`
* `c:-digit?`
* `c:-lowercase?`
* `c:-uppercase?`
* `c:-visible?`
* `c:-vowel?`
* `c:-whitespace?`
All of these take a character and return either a `TRUE` or
`FALSE` flag.
## Conversions
A few words are provided to convert case. Each takes a character
and returns the modified character.
* `c:to-lower`
* `c:to-number`
* `c:to-upper`
* `c:toggle-case`
RETRO also has `c:to-string`, which takes a character and
creates a new temporary string with the character.
## I/O
Characters can be displayed using `c:put`.
```
$a c:put
```
With the default system on BSD, Linux, and macOS (and other
Unix style hosts), `c:get` is provided to read input. This
may be buffered, depending on the host.