Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!tekcrl!tekgvs!toma From: toma@tekgvs.LABS.TEK.COM (Tom Almy) Newsgroups: comp.lang.forth Subject: Re: Nuke separate CONTEXT and CURRENT Message-ID: <7197@tekgvs.LABS.TEK.COM> Date: 27 Mar 90 22:15:14 GMT References: <9003271432.AA19673@jade.berkeley.edu> Reply-To: toma@tekgvs.LABS.TEK.COM (Tom Almy) Organization: Tektronix, Inc., Beaverton, OR. Lines: 78 In article <9003271432.AA19673@jade.berkeley.edu> wmb@MITCH.ENG.SUN.COM writes: >I have recently begun to think that the notion of separate search >(CONTEXT) and compilation (CURRENT) vocabularies is bogus. >Back in the old days, before run-time search order specification >(ALSO/ONLY), separate search and compilation vocabularies may have >bought you something worthwhile, but I'm not sure just what. I don't see what the problem is here. The CURRENT vocabulary does not have anything to do dictionary searches, but just what vocabulary new definitions go in. CONTEXT is a problem with Forths which implement ALSO/ONLY because in these cases CONTEXT is really a list of vocabularies and not a single vocabulary. My personal preference is a vocabuary stack. The language STOIC had this (and several other excellent features that should have become part of Forth IMHO). The word > popped the vocabuarly stack. Vocabularies by convention had names ending in "<". The STOIC< vocabulary was implicitly at the bottom the vocabulary stack and could not be popped. Executing a vocabulary name pushed that vocabulary onto the stack. Vocabulary functions were "immediate" -- when you needed words from a particular vocabulary, you would simply enclose the region like so: FOO< words... > Very visually appealing! But even in STOIC, DEFINITIONS would make the current vocabulary be the vocabulary on top of the vocabulary stack. >These days, they just make things confusing, especially considering the >Forth-83 requirement that : must set CONTEXT to CURRENT . I never liked that either. (Read on in my example ) >Can anybody think of some arguments in favor of the separation of >CONTEXT and CURRENT ? I would particularly like to hear of commonly- >occurring situations where the separation helps, but strange or uncommon >situations might be interesting as well. Well, in the assembler, ASSEMBLER words typically are not built from ASSEMBLER words (that would mean that the assembler would be made of CODE words, an interesting thought (and the reality in STOIC!) In my Native Code Compiler, the words which are searched in "Native Code Compile" state have the same names as the standard Forth words. I put these words in a vocabulary called COMPOPS (back in the old days of vocabulary trees, this vocabulary had to be "sealed"). Anyway, COMPOPS words almost never refer to other COMPOPS words, thus I almost never want CONTEXT=CURRENT. A typical COMPOPS word (from memory): COMPOPS DEFINITIONS : 1+ \ native code compile time definition of 1+ FORTH \ make context FORTH again. LIT? IF \ literal on top of stack? LIT> 1+ >LIT \ do addition at compile time ELSE \ otherwise must compile code to do addition 1ARG \ generate necessary code to put top of stack in reg TSREG ASM INC FORTH \ increment top of stack register \ TSREG is function that returns \ current top of stack register THEN ; There we go. No COMPOPS words used, but ASSEMBLER and FORTH words were used. The headers for the FORTH words which are internal to the NCC are excised before the compiler module is saved. >How about historical arguments? Sure. This is the way it has always been done. >I have just about convinced myself that there is no absolute need for the >separation, since it is always possible to explicitly set the search >order to any desired order at any time, perhaps inside brackets ( [ .. ] ). I'm happy with the status quo. Tom Almy toma@tekgvs.labs.tek.com Standard Disclaimers Apply