Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!ucsd!sdcc6!ir230 From: ir230@sdcc6.ucsd.edu (john wavrik) Newsgroups: comp.lang.forth Subject: Re: FORTH Modules: current confusion? Keywords: modules; dictionary structure; compiler mods Message-ID: <5746@sdcc6.ucsd.edu> Date: 14 Dec 89 16:16:13 GMT References: <5596@sdcc6.ucsd.edu> <6708@tank.uchicago.edu> Organization: University of California, San Diego Lines: 116 Keith Waclena writes: # My problem is this: Schorre's code is (I think) fig-FORTH and needs to # be updated to FORTH-83 for the systems I have around. Here is # Schorre's complete code: # # : internal current @ @ ; # : external here ; # : module pfa lfa ! ; # My two guesses as to where my problem lies are as follows: lack of # understanding of current (what exactly *does* it point to, anyway? # This is not at all clear from the standard document.), or perhaps a # problem with hashed dictionaries? Your analysis is correct. After 1983 the dictionary was no longer required to be a simple linked list. Systems like F83 elected to increase compilation speed by putting names in one of several linked lists ("threads") using a hashing scheme -- the number of threads usually varies from 4 (in F83) to 512 (in a version of Forth written by Guy Kelly -- the chairman of the 1983 Standards Team) and varies from system to system, as does the hashing function. The Guiness Book of Records lists Bjork Fjorn of Norway as the programmer with the most threads in his version of Forth -- 1,203,456. (Bjork admits that he does not use vocabularies very often.) The link field now only refers to the previous word IN A GIVEN THREAD (so God only knows what you relinked!). There are also some other even more subtle problems in adapting the code. In figForth, : INTERNAL CURRENT @ @ ; would have given the name field address of the most recent entry in the current vocabulary : EXTERNAL HERE ; would have given the address of name field of the next word to be defined. : MODULE PFA LFA ! ; would have set the link field of the first external entry to point to the entry before the first internal entry. In F83 the link fields point to the link field of the previous entry in the same thread -- but there is a view field that comes before the link field. So the definition of EXTERNAL would need modification even if the dictionary were a simple linked list (which it isn't). ------- There is another simple solution to your problem: alter the name field so that hidden words are not found : KILL 128 ' >NAME C! ; KILL will set the character count of the name field of to 0. You can kill anything you want never to be found in a dictionary search (relinking the dictionary has the same effect). Note: this is not portable and violates the Forth-83 Standards, but it does work on F83. (You can also use a mechanism like that found in the definition of WORDS to obliterate all names between two addresses.) ------- What you are supposed to do these days is to handle all dictionary manipulation by vocabularies (rather than manipulating dictionary links directly). Each time a new local environment is created, the variables (and words) local to that environment are to be put in a vocabulary. In F83 your example can be handled like this: 1. VOCABULARY TEMP TEMP ALSO DEFINITIONS \ internal VARIABLE FOO 2. FORTH DEFINITIONS \ external : RESET 0 FOO ! ; : INC 1 FOO +! ; : HMM FOO ? ; 3. PREVIOUS FORTH DEFINITIONS \ module In step 1, a new vocabulary called TEMP is installed and placed in the search order. The variable FOO is put in this vocabulary. In step 2, the FORTH vocabulary is put on top of TEMP in the search order and is also made the current vocabulary for the new definitions. In step 3 the TEMP vocabulary is eliminated from the search order. NOTES: 1. The words used cannot be easily simplified. In particular : INSTALL VOCABULARY TEMP TEMP ALSO DEFINITIONS ; cannot be used to create the new vocabulary, since "TEMP" is not in the dictionary. 2. During stage 2, the FORTH dictionary occurs in the search order before TEMP -- thus if FORTH has a word "foo" it will be used rather than the word in TEMP. This is one of the major disadvantages of this method. 3. The vocabulary mechanisms used above were part of a proposal to the 1983 Standards. They are included in F83 but are not part of the Standard. 4. The example assumes the FORTH vocabulary but can be easily modified to apply to any current vocabulary. If you are willing to accept tampering with the linking of a particular version of Forth then very powerful things can still be done -- but not portably and not as simply. John J Wavrik jjwavrik@ucsd.edu Dept of Math C-012 Univ of Calif - San Diego La Jolla, CA 92093