16.6.1.2197 SET-ORDER SEARCH
Set the search order to the word lists identified by widn ... wid1. Subsequently, word list wid1 will be searched first, and word list widn searched last. If n is zero, empty the search order. If n is minus one, set the search order to the implementation-defined minimum search order. The minimum search order shall include the words FORTH-WORDLIST and SET-ORDER. A system shall allow n to be at least eight.
Implementation:
: SET-ORDER ( wid1 ... widn n -0 )
DUP -1 = IF
DROP <push system default word lists and n>
THEN
DUP #order !
0 ?DO I CELLS context + ! LOOP
;
Testing:
T{ GET-ORDER SET-ORDER -> }T
T{ GET-ORDER -> get-orderlist }T T{ get-orderlist DROP get-orderList 2* SET-ORDER -> }T
T{ GET-ORDER -> get-orderlist DROP get-orderList 2* }T
T{ get-orderlist SET-ORDER GET-ORDER -> get-orderlist }T
: so2a GET-ORDER get-orderlist SET-ORDER ;
: so2 0 SET-ORDER so2a ;
T{ so2 -> 0 }T \ 0 SET-ORDER leaves an empty search order
: so3 -1 SET-ORDER so2a ;
: so4 ONLY so2a ;
T{ so3 -> so4 }T \ -1 SET-ORDER is the same as ONLY
ContributeContributions
LeonWagner [164] Typo in stack commentComment2020-11-04 17:07:33
The extra 0 at the end of this stack comment looks like a typo: : SET-ORDER ( wid1 ... widn n -0 )
Should be: : SET-ORDER ( wid1 ... widn n -- )
lmr [320] Negative n values Request for clarification2023-12-19 22:16:40
If n is negative and <= -2, is it ambiguous, or a mandatory error? E.g. can I use "-2 SET-ORDER" to allow the user (as well as system primitives) to reset the search order to the default of my implementation?