If you have an existing wordlist in constant foo-wordlist and
want to push it on the search order, here’s how you do it:
foo-wordlist >order ... \ code that may use words from foo-wordlist previous \ now the search order is back to where we started
If instead you have a vocabulary foo, the same task can be
accomplished as follows:
also foo ... \ code that may use words from foo previous \ now the search order is back to where we started
Also, if you need only one or a few words from foo, you can use
the scope recognizer (rec-scope, see Default recognizers)
and write foo:word. Currently the scope recognizer only
uses vocabularies for the scope, not wordlists.
A common usage is to define implementation words (which would be
private in other programming languages) in a separate wordlist, and
(public) interface words in a wordlist for public words (usually
forth-wordlist). This can be achieved as follows:
wordlist constant foo-wordlist \ the implementation wordlist get-current ( wid ) foo-wordlist >order definitions \ foo-wordlist is now visible and definitions go into it ... \ define implementation words ( wid ) set-current \ foo-wordlist is visible, but definitions go into wid ... \ define interface words previous \ search order and current wordlist are back to where we started
The same can be done with vocabularies as follows:
vocabulary foo \ the implementation vocabulary get-current ( wid ) also foo definitions \ foo is now visible and definitions go into it ... \ define implementation words ( wid ) set-current \ foo is visible, but definitions go into wid ... \ define interface words previous \ search order and current wordlist are back to where we started
If you want to define just one word in a given wordlist, you can do it as follows:
foo-wordlist in-wordlist : bar ... ;
For vocabularies, the corresponding usage is: