16.6.1.2192 SEARCH-WORDLIST SEARCH

( c-addr u wid -- 0 | xt 1 | xt -1 )

Find the definition identified by the string c-addr u in the word list identified by wid. If the definition is not found, return zero. If the definition is found, return its execution token xt and one (1) if the definition is immediate, minus-one (-1) otherwise.

See:

Rationale:

When SEARCH-WORDLIST fails to find the word, it does not return the string, unlike FIND. This is in accordance with the general principle that Forth words consume their arguments.

Testing:

ONLY FORTH DEFINITIONS
VARIABLE xt ' DUP xt !
VARIABLE xti ' .( xti ! \ Immediate word

T{ S" DUP" wid1 @ SEARCH-WORDLIST -> xt  @ -1 }T
T{ S" .("  wid1 @ SEARCH-WORDLIST -> xti @  1 }T
T{ S" DUP" wid2 @ SEARCH-WORDLIST ->        0 }T

ContributeContributions

lmravatar of lmr [318] NDCS xtRequest for clarification2023-12-17 18:15:48

When searching for a word with NDCS, what XT should be returned? An xt dependent on STATE at the time of the call as in the spec for FIND, a state-smart xt...? I'm surprised no one asked while FIND has lots of comments

AntonErtlavatar of AntonErtl

One interesting difference between FIND and SEARCH-WORDLIST is that FIND actually mentions that a different result can be returned depending on STATE while SEARCH-WORDLIST does not. Therefore Gforth always returns an xt representing the interpretation semantics (or an xt that throws -14 when executed if the word does not have interpretation semantics in Gforth). Nobody has complained about that yet, indicating that people probably don't search for words without interpretation semantics or words with non-default compilation semantics with SEARCH-WORDLIST.

There are ongoing discussions about topics involving semantics, xts and related topics, and they are unlikely to be resolved soon, so I doubt you will get a definite answer to your request soon.

Reply New Version