the NEED word system from an article in Forth Dimensions Vol.V#3 by Will Baden adapted for newer F83 by Gary Bergstrom 10/08/87 \ NEED WORD SYSTEM DOS DEFINE NEED.DIR DEFINE TOOLS.BLK VISA NEED.BLK VIEW++ VIEWS TOOLS.BLK ONLY FORTH ALSO HIDDEN ALSO DEFINITIONS 2 3 THRU 1 4 DIRECTORY MASTER MASTER ONLY FORTH ALSO \ Easy directory system scr 20FEB86GEB : ANOTHER BL WORD DUP C@ ; : SET-FILE (S -- scr ) BASE @ >R DECIMAL BL WORD NUMBER DROP [ DOS ] FROM R> BASE ! ; : PURSUE ( -- f true=found ) BEGIN ANOTHER IF PAD DUP C@ 1+ COMPARE IF BL WORD DROP BL WORD DROP FALSE ELSE TRUE EXIT THEN THEN UNTIL FALSE ; : LOOKUP BLK @ >R >IN @ >R FILE @ >R [ DOS ] CLOSE-BOTH NEED.DIR FALSE -ROT 1+ SWAP DO I BLK ! >IN OFF PURSUE IF NOT LEAVE THEN LOOP CLOSE-BOTH IF SET-FILE R> FILE ! R> >IN ! R> BLK ! ELSE R> >FILE PAD COUNT TYPE TRUE ABORT" is not in catalog" THEN ; \ Easy dictionary 20FEB86GEB : SUBJECT BL WORD COUNT PAD PLACE LOOKUP ; 0. 2CONSTANT %DIR : >DIRECTORY ['] %DIR >BODY 2! ; ONLY FORTH DEFINITIONS ALSO HIDDEN ALSO : DIRECTORY CREATE , , DOES> 2@ >DIRECTORY ; : NAME %DIR SUBJECT ; : VIEW [ DOS ] >IN @ DEFINED NIP IF >IN ! VIEW ELSE >IN ! NAME IN-FILE @ >FILE LIST THEN ; : NEED FILE @ >IN @ [ DOS ] DEFINED NIP IF 2DROP ELSE CLOSE-BOTH >IN ! NAME LOAD >FILE THEN ; : RUN >IN @ NEED >IN ! ; : CAT [ DOS ] FILE @ >R NEED.DIR [ DOS ] %DIR 1+ SWAP DO I LIST LOOP R> >FILE ; The NEED directory word system examples: NEED CASE ( load CASE ) VIEW (( ( look at word (( ) 1 2 3 4 RUN 4DROP ( load 4DROP and then run it ) NAME TESTING 25 COPY ( copys screen with testing on it to the current file screen 25 ) MASTER a directory word which sets screen 1 to 1 to contain the catalog entries. Easy directory system ANOTHER get the next word from input SET-FILE sets the in file and gets the right screen number PURSUE find the target word in the catalog LOOKUP use PURSUE and SET-FILE to find a word in the catalog and set the correct file. (or issue error) saves FILE and restores it. Easy directory system SUBJECT get next input stream word to pad %DIR double number containing low and high scr numbers of catalog in NEED.DIR >DIRECTORY store double number into %DIR constant DIRECTORY make a word whose run time is to set %DIR NAME <name> lookup <name> in catalog, set IN-FILE, and leave screen number. VIEW <name> lookup <name> and list it, if in memory then do the old VIEW command NEED <name> if not already defined, lookup <name> and load it RUN <name> do a NEED <name> and then run it CAT print catalog from NEED.DIR