6.10.4 Values

A Value behaves like a Constant, but it can be changed. TO is a parsing word that changes a Values. In Gforth (not in Standard Forth) you can access (and change) a value also with >body.

Here are some examples:

12 Value APPLES     \ Define APPLES with an initial value of 12
34 TO APPLES        \ Change the value of APPLES. TO is a parsing word
1 ' APPLES >body +! \ Increment APPLES.  Non-standard usage.
APPLES              \ puts 35 on the top of the stack.
Value ( w "name" –  ) core-ext “Value”

Define name with the initial value w; this value can be changed with to name or ->name.

name execution: – w2

AValue ( w "name" –  ) gforth-0.6 “AValue”

Like value, but defines a value for an address (this only makes a difference in the cross-compiler).

2Value ( d "name" –  ) double-ext “two-value”
fvalue ( r "name" –  ) floating-ext “f-value”

Define name ( -- r1 ) where r1 initially is r; this value can be changed with to name or ->name.

TO ( value "name" –  ) core-ext “TO”

changes the value of name to value

+TO ( value "name" –  ) gforth-1.0 “+TO”

increments the value of name by value

value! ( x xt-value –  ) gforth-experimental “to-store”

Changes the value of xt-value to x

value+! ( n xt-value –  ) gforth-experimental “value-plus-store”

Increments the value of xt-value by n