Previous: Compilation token, Up: Tokens for Words

5.11.3 Name token

Gforth represents named words by the name token, (nt). Name token is an abstract data type that occurs as argument or result of the words below.

The closest thing to the nt in older Forth systems is the name field address (NFA), but there are significant differences: in older Forth systems each word had a unique NFA, LFA, CFA and PFA (in this order, or LFA, NFA, CFA, PFA) and there were words for getting from one to the next. In contrast, in Gforth 0...n nts correspond to one xt; there is a link field in the structure identified by the name token, but searching usually uses a hash table external to these structures; the name in Gforth has a cell-wide count-and-flags field, and the nt is not implemented as the address of that count field.

find-name       c-addr u – nt | 0         gforth       “find-name”

Find the name c-addr u in the current search order. Return its nt, if found, otherwise 0.

latest       – nt         gforth       “latest”

nt is the name token of the last word defined; it is 0 if the last word has no name.

>name       xt – nt|0         gforth       “to-name”

tries to find the name token nt of the word represented by xt; returns 0 if it fails. This word is not absolutely reliable, it may give false positives and produce wrong nts.

name>int       nt – xt         gforth       “name-to-int”

xt represents the interpretation semantics of the word nt. If nt has no interpretation semantics (i.e. is compile-only), xt is the execution token for ticking-compile-only-error, which performs -2048 throw.

name>comp       nt – w xt         gforth       “name-to-comp”

w xt is the compilation token for the word nt.

name>string       nt – addr count         gforth       “name-to-string”

addr count is the name of the word represented by nt.

id.       nt –         gforth       “i-d-dot”

Print the name of the word represented by nt.

.name       nt –         gforth-obsolete       “dot-name”

Gforth <=0.5.0 name for id..

.id       nt –         F83       “dot-i-d”

F83 name for id..