Level 3, lesson 5

# 3.5 Using values

Not only variables and arrays of variables are stored in the Variable Area, but also values. A value is a cross-over between a variable and a constant. May be this example will give you an idea:

declaration:

           variable a      ( No initial value)
           1 constant b    ( Literal expression assigned at compiletime)
           2 b + value c   ( Expresssion assigned at runtime)

fetching:

           a @             ( Variable throws address on stack)
           b               ( Constant throws value on stack)
           c               ( Value throws value on stack)

storing:

           2 b + a !       ( Expression can be stored at runtime)
                           ( Constant cannot be reassigned)
           2 b + to c      ( Expression can be stored at runtime)

In many aspects, values behave like variables and can replace variables. The only thing you cannot do is make arrays of values.

A value is not a literal expression either, so you can't use them to size arrays. In fact, a value is a variable that behaves in certain aspects like a constant.

Why use a value at all? Well, there are situations where a value can help:

- When converting Forth programs (replacing constants)
- When a constant CAN change during execution

Note that although 'VALUE' and 'TO' are aliases, it is more portable and more readable to use 'VALUE' for declaration and 'TO' for reassignment. Note that each 'TO' or 'VALUE' consumes a little memory when compiling, so reassignments have to be rare. It is certainly not a good idea to replace all variables by values.