Node:Anonymous Definitions, Next:Supplying names, Previous:Colon Definitions, Up:Defining Words
Sometimes you want to define an anonymous word; a word without a
name. You can do this with:
:noname-- xt colon-sys core-ext ``colon-no-name''
This leaves the execution token for the word on the stack after the
;. 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
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
noname-- gforth ``noname''
xt is the execution token of the last word defined.
latestxt-- xt gforth ``latestxt''
The previous example can be rewritten using
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 does not work for combined words, though. It also has
the useful property that is 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.