GARTHWILSON wrote:
I haven't paid much attention, because I theorize that a variable initialized to zero is just about as likely to produce wrong results as any other number, if the programmer forgets to have his program initialize it before reading it.
I agree. That's not why Fleet Forth initializes variables to zero. I did it to save a few bytes. Fleet Forth's vocabularies have the address of the latest word's link field in the first cell, the address of the parent vocabulary in the second cell, and use the third cell as part of the
VOC-LINK chain.
A new vocabulary will have a zero in its first cell ( because it is empty ), so
VOCABULARY is defined like this:
Code:
HEX
: VARIABLE ( -- )
CREATE 0 , ;
: VOCABULARY ( -- )
VARIABLE // LATEST WORD'S LFA
CURRENT @ , // PARENT VOCABULARY
HERE VOC-LINK DUP @ , ! // VOC-LINK CHAIN
DOES>
CONTEXT ! ;
Note: the
// ( double slash) is a workaround, I first saw in Blazin' Forth, for the C64 not having
\ ( backslash)
barrym95838 wrote:
I am more troubled by the portability issues of stating "two bytes" than I am on the issue of initialization.
A good reason to define variable as
Code:
: VARIABLE ( -- )
CREATE 0 , ;
since that is independent of cell width.