Proposal: WLSCOPE -- wordlists switching made easier
This proposal has been moved into this section. Its former address was: /standard/search
This page is dedicated to discussing this specific proposal
ContributeContributions
enoch [20] WLSCOPE -- wordlists switching made easierProposal2016-06-18 04:19:03
Proposal
It is proposed that Forth 200x compliant implementations would be required to offer a deferred word, wlscope (addr len -- addr' len' wid), whose initial implementation is get-current. All the mechanisms that create new dictionary entries would be required to pass the new name ( addr len ) through wlscope to obtain the destination wordlist ( wid ); the name itself may also be altered, hence ( addr' len' ).
Problem
Make it easier to manage inclusion of created words on different wordlists. All large software projects carefully regulate their name spaces. Openfirmware, for example, to separate between the "public" words and the "private" words often groups them as follows:
only forth also hidden also definitions
...
also forth definitions
...
With wlscope we would like to take this one step further and allow wordlist switches to be driven by the new name itself, in a way that is completely under the programmer control, through a chain of user defined wlscope functions which analyze and perhaps modify the newly created name and determine to which wordlist it is to be added.
Typical use
The following shows two wlscope "rules" and how to chain them.
Put helper (factorization) words onto a _local wordlist
\ Wordlist scope that puts words with underscore (_) prefix
\ on a _local wordlist.
:noname ( addr len -- addr' len' wid )
2dup
1 > if \ name length check
s" _" tuck icompare if \ name prefix check
_local exit
then
else
drop
then
[ ' wlscope defer@ ]l execute
; is wlscope
Grow a special use gui wordlist
vocabulary gui
:noname ( addr len -- addr' len' wid )
2dup
4 > if \ name length check
s" gui_" tuck icompare if \ name prefix check
swap 4 + swap 4 - \ remove gui_ prefix
gui exit
then
else
drop
then
[ ' wlscope defer@ ]l execute
; is wlscope
Thus,
: _helper ... ;
would automatically add _helper to the _local wordlist while
: gui_init-gl ... ;
would add init-gl to the gui wordlist.
Reference Implementation
VM asm code at: core/create/docreate.asm and elsewhere.
Experience
amforth and amforth-shadow