IamRob wrote:
I do something similar with my Line Load definition. The interpreter pointer points to the beginning of most recently load buffer, and I adjust >IN to a multiple of C/L (chars per line), where to start an interpretation of a word.My Line Load has the word definition of "LL" and has the inputs of SCR and LINE.
Fleet Forth's LINELOAD has the stack effect shown in the Forth-83 Standard's section 'UNCONTROLLED REFERENCE WORDS'. It takes the line number and the number of the screen to load.
Code:
: LINELOAD ( LINE# BLK# -- )
DUP 0=
ABORT" CAN'T LOAD 0"
RB DECIMAL
BLK 2@ 2>R
BLK ! C/L * >IN !
INTERPRET 2R> BLK 2! ;
Here is LOAD
Code:
: LOAD ( BLK# -- )
0 SWAP LINELOAD ;
As for why LINELOAD has BLK 2@ and BLK 2! , here are the definitions of BLK and >IN .
Code:
VARIABLE BLK HERE 0 , CONSTANT >IN
IamRob wrote:
Note also I programmed into Forth the ability to ignore a word if a word definition already exists to prevent duplicate loads of a definition.
The FORTH 2012 Standard has the word [DEFINED] to return a true flag if the word following [DEFINED] in the text stream is defined in the specified search order. Some other Forths have something similar. Used with conditional compilation, it is handy to avoid recompiling an oft used utility word which may be defined in multiple lexicons. However, it is a facility which is under the control of the programmer.