Sometimes you want to define an anonymous word; a word without a name. You can do this with:
This leaves the execution token for the word on the stack after the
closing ;
. Here’s an example in which a deferred word is
initialised with an xt
from an anonymous colon definition:
Defer deferred :noname ( ... -- ... ) ... ; IS deferred
Gforth provides an alternative way of doing this, using two separate words:
The next defined word will be anonymous. The defining word will
leave the input stream alone. The xt of the defined word will
be given by latestxt
, its nt by latestnt
(see Name token).
xt is the execution token of the most recent word defined in the current section.
The previous example can be rewritten using noname
and
latestxt
:
Defer deferred noname : ( ... -- ... ) ... ; latestxt IS deferred
noname
works with any defining word, not just :
.
latestxt
also works when the last word was not defined as
noname
. It also has the useful property that it is valid as
soon as the header for a definition has been built. Thus:
latestxt . : foo [ latestxt . ] ; ' foo .
prints 3 numbers; the last two are the same.