October 2024
Intermediate to advanced
272 pages
6h 54m
English
Following the tradition of the C language, a Forth character is simply an integer number optionally represented as a single-quoted literal. Characters can be subtracted, incremented, and compared, which is helpful, but they can also be added, divided, and multiplied, which is not. Forth giveth you a lot of power over characters—use it wisely. For instance, you can define a word to check if a character represents a decimal digit:
| | : ?DIGIT ( c -- flag ) [CHAR] 0 [CHAR] 9 1+ WITHIN ; |
| | 'a' ?DIGIT .↩ 0 ok |
| | '7' ?DIGIT .↩ -1 ok \ True |
| | BL ?DIGIT .↩ 0 ok |
In this example, the word [CHAR] ( "name" -- n ) converts a literal into an integer number, according to the current character ...
Read now
Unlock full access