Arriving to Memory Operations
Isn’t it amazing that you read twenty pages of the Forth story without seeing a word about variables or arrays? Forth works great without variables and arrays. But it’s even better with them.
Variables
Forth variables are named memory locations. You must create them explicitly and initialize them after or at the time of creation (the latter option works only in fig-Forth). The location consists of one or two cells (a 2-variable). In some dialects of Forth, single-byte variables exist. A 2-variable can be accessed piecewise, one cell at a time.
The name of a variable resolves into its address in memory. To create a variable, use the words VARIABLE or 2VARIABLE, followed by the variable name. (Compare constant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access