16.6.1.2197 SET-ORDER SEARCH

( widn ... wid1 n -- )

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:

This is the complement of E.16.6.1.1647 GET-ORDER.

: 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 OVER      -> GET-ORDER wid1 @ }T
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

LeonWagneravatar of 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 -- )

Reply New Version

lmravatar of 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?

AntonErtlavatar of AntonErtl

It's not specified, so systems can do whatever they want. Giving it some sane behaviour, as you suggest, appears to be a good idea.

Checking three systems, I see

  • gforth 0.7.3 does not produce an error, but the resulting search order does not include order or set-order (and is probably corrupt, word completion produces an "invalid memory address" throw).

  • SwiftForth 4.0.0-RC52 exits with a Segmentation fault.

  • VFX Forth 64 5.11 RC2 appears to handle -2 set-order in the same way as -1 set-order.

Reply New Version