Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM Newsgroups: comp.lang.forth Subject: Re: FORTH Modules: current confusion? Message-ID: <8912140448.AA10753@jade.berkeley.edu> Date: 14 Dec 89 04:40:59 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 78 > : internal current @ @ ; > : external here ; > : module n>link ! ; > > ... [doesn't work in F83] ... because the F83 dictionary is multiply-threaded. Instead of a single linked list, a vocabulary is #THREADS (usually 4) linked lists. The thread to search when looking for a word is determined by a hash function, which happens to be the lower n bits of the first character in the name. It also fails because the "here" in external is assumed to point to the name field address of the next word defined after "external". In systems where the name field is indeed the first thing in a word, this is okay. However, in F83, both the "view" field and the link field precede the name field. In order to implement the module function in F83, you will need to do the following (assuming that you don't change the current vocabulary in the process). : internal ( -- hidden-start-address ) here ; : external ( -- hidden-end-address ) here ; : module ( start end -- ) current @ #threads 2* bounds do 2dup i remove 2 +loop ; Where REMOVE works as follows: remove ( start-adr end-adr list-head -- ) Traverse the linked list, removing entries between start and end. : remove ( start-adr end-adr list-head -- ) \ Find node just above "end" swap >r ( start-adr list-head ) ( r: end ) begin dup @ r@ > while @ repeat ( start-adr node' ) r> drop ( start-adr node' ) \ Find node just below "start" swap >r dup ( node' node' ) ( r: start-adr ) begin @ dup r@ < until ( node' node'' ) r> drop ( node' node'' ) swap ! ( ) ; Warning: the preceding code has not been tested. If it has bugs, finding them is left to the reader as an exercise. I don't know about F-PC. I suspect that it works similarly to F-83. Another solution strategy would be to use the vocabulary search mechanism, something like this: vocabulary temporary : internal ( -- adr ) also temporary definitions here ; : external ( -- ) previous context @ temporary also context ! definitions ; : module ( adr -- ) context @ previous ( old-context ) context @ swap context ! ( temporary-adr ) trim ; This depends on the existence of the F83 word: TRIM ( adr voc-adr -- ) Unlinks all words defined after "adr" in the vocabulary "voc-adr" Mitch