16.6.1.1550 FIND SEARCH
Extend the semantics of 6.1.1550 FIND to be:
( c-addr -- c-addr 0 | xt 1 | xt -1 )
Find the definition named in the counted string at c-addr. If the definition is not found after searching all the word lists in the search order, return c-addr and zero. If the definition is found, return xt. If the definition is immediate, also return one (1); otherwise also return minus-one (-1). For a given string, the values returned by FIND while compiling may differ from those returned while not compiling.
See:
Implementation:
Assuming
#order
and context
are defined as per E.16.6.1.1647 GET-ORDER.
: FIND ( c-addr -- c-addr 0 | xt 1 | xt -1 )
0 ( c-addr 0 )
#order @ 0 ?DO
OVER COUNT ( c-addr 0 c-addr' u )
I CELLS context + @ ( c-addr 0 c-addr' u wid )
SEARCH-WORDLIST ( c-addr 0; 0 | w 1 | q -1 )
?DUP IF ( c-addr 0; w 1 | w -1 )
2SWAP 2DROP LEAVE ( w 1 | w -1 )
THEN ( c-addr 0 )
LOOP ( c-addr 0 | w 1 | w -1 )
;
0 ( c-addr 0 )
#order @ 0 ?DO
OVER COUNT ( c-addr 0 c-addr' u )
I CELLS context + @ ( c-addr 0 c-addr' u wid )
SEARCH-WORDLIST ( c-addr 0; 0 | w 1 | q -1 )
?DUP IF ( c-addr 0; w 1 | w -1 )
2SWAP 2DROP LEAVE ( w 1 | w -1 )
THEN ( c-addr 0 )
LOOP ( c-addr 0 | w 1 | w -1 )
;
Testing:
ContributeContributions
lmr [327] diff from CORE FIND?Request for clarification2023-12-31 13:04:17
Maybe I'm missing something obvious, but how is this an extension of CORE FIND? It seems like exactly the same wording.